Address class: class definition and implementation : Class Basics « Class « C++






Address class: class definition and implementation

Address class: class definition and implementation
#include <iostream>
#include <cstring>
using namespace std;

class Address {
  char name[40];
  char street[40];
  char city[30];
  char state[3];
  char zip[10];
public:
  void store(char *n, char *s, char *c, char *t, char *z);
  void display();
};

void Address::store(char *n, char *s, char *c, char *t, char *z)
{
  strcpy(name, n);
  strcpy(street, s);
  strcpy(city, c);
  strcpy(state, t);
  strcpy(zip, z);
}

void Address::display()
{
  cout << name << endl;
  cout << street << endl;
  cout << city << endl;
  cout << state << endl;
  cout << zip << endl;
}

int main()
{
  Address a;

  a.store("C", "11 Lane", "W", "In", "4");

  a.display();

  return 0;
}


           
       








Related examples in the same category

1.Class forward declarationClass forward declaration
2.Simplest class definitionSimplest class definition
3.A simple class with member variable, constructor, destructorA simple class with member variable, constructor, destructor
4.Declare class instanceDeclare class instance
5.Constructor: different parameter typeConstructor: different parameter type
6.Declare Class instance and use themDeclare Class instance and use them
7.Assign object1 to object2Assign object1 to object2
8.Init Object arrayInit Object array