*struct members are public by default *class members are private by default *both can have -constructors -destructors -member variables -member function *often use structs for data, use classes for objects ----------------------------------- #include int main() { struct personaldata { char *firstname; char *lastname; char *birthday; // in the format of MM/DD/YYYY int phonenum; }; personaldata personone; // declaring variable of type personaldata //populate personone with data personone.firstname = "John"; personone.lastname = "Doe"; personone.birthday = "12/30/1978"; personone.phonenum = 5855555; //print the data out cout <<"First name :" << personone.firstname << endl; cout <<"Last name :" << personone.lastname << endl; cout <<"DOB :" << personone.birthday << endl; cout <<"phone number :" << personone.phonenum << endl; return 0; } ------------------------------------- #include class crectangle { int x, y; //data member public: void set_values (int, int); //member function int area (void) { return (x*y); } }; void crectangle::set_values(int a, int b) /*::scope operator, specify the class to which the member being declared belongs to. this is also an assignment.*/ { x=a; y=b; } int main() { crectangle rect, rectb;// declares rect as an object rect.set_values(3,4);// assigns values to rect rectb.set_values(2,3); cout <<"Area :"<< rect.area() << endl;// outputs result cout <<"Area :"<< rectb.area() << endl; return 0; } -------------------------------------- #include #include class date { private: int month; int day; int year; public: date(int = 7, int = 4, int = 2001);//a member function - constructor void setdate(int,int,int);//a member function void showdate(); }; date::date(int mm, int dd, int yyyy)//constructor that intitializes { month = mm; day = dd; year = yyyy; return; } void date::showdate()//displays { cout << "The date is "; cout << setfill('0')//ensures values correspond to the conventional dates << setw(2) << month <<'/' << setw(2) << day << '/' << setw(2) << year % 100 // extract the last two digits << endl; return; } int main() { date a, b, c(4, 1, 1998); //declares 3 objects b.setdate(12,25,2002);//assigns values to b data a.showdate(); b.showdate(); c.showdate(); return 0; } --------------------------------------------------- char word[10]; char word2[10]; strcpy(word, "Maggie"); strcpy(word2, "Bad"); int len=strlen(word); cout << len << endl;