1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
# include <iostream> // An header file for I/O operations
using namespace std; // For Uniqueness
class Person
{
class Student
{
class Date
{
int day;
char * month;
int year;
// class attributes: they are private by default
public:
void ManageDate(int d, char* M, int y) //// initialization of actual parameters
{
day=d;
month=M;
year= y;
}
Date() //default constructor
{
day=0;
month="";
year=0;
}
Date(int D, char* m, int Y)
{
day=D;
month=m;
year = Y;
}
int getDay()
{
return day;
}
int getYear()
{return year;
}
char * getMonth()
{
return month;
}
};
//////////// Class Attributes Starts from Here ////////////
char * FirstName; // Non-static variable
string Surname;
int Age;
static int Level; // A static variable
Date DOB; // An instance of class Date as an attribute of class Student
/////////////// Class Attributes Ends Here ///////////////
// The class attributes are public by default////////
public: //// change of access mode modifier from private to public
Student()
{
}
Student(int D, char* m, int Y):DOB(D,m,Y)
{
FirstName="";
Surname="";
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}
Student(char * FName, Date D) //// constructor with one argument/parameter
{
FirstName=FName;
Surname="";
DOB=D;
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}
Student(char * FName, string SName,int D, char* m, int Y):DOB(D,m,Y) //// constructor with two arguments/parameters
{
FirstName=FName;
Surname=SName;
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}
Student(char * FName, string SName, int age) //// constructor with two arguments/parameters
{
FirstName=FName;
Surname=SName;
Age=age;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}
void SetFullNames(char * FName, string SName)
{
FirstName = FName;
Surname = SName;
}
void SetAge(int age)
{
Age=age;
}
/////// User-defined functions to initialize class attributes
char * GetFName()
{
return FirstName;
}
string GetSName()
{
return Surname;
}
int GetAge()
{
return Age;
}
int GetLevel()
{
return Level;
}
/////////////// User-defined functions to return initialized class attributes
////////////// to the caller
void displayFullName()
{
cout<<GetFName()<<" "<<GetSName()<<endl;
}
void displayParameters()
{
cout<<GetFName()<<endl;
cout<<GetSName()<<endl;
cout<<GetAge()<<endl;
cout<<GetLevel()<<endl;
}
Date GetDate()
{
return DOB;
}
};
//////// end of class student
Student UniStudent;
string Address;
public:
Person(Student U, string add):UniStudent(U)
{
Address = add;
}
Person(char * FName, string SName,int D, char* m, int Y, string Add):UniStudent(FName, SName,(D,m,Y))
{
Address=Add;
}
string GetAddress(){return Address;}
Student GetStudent(){return UniStudent;}
void display()
{
UniStudent.displayParameters();
cout<<GetAddress()<<endl;
}
};
int Person::Student :: Level = 100; // Initialization of class variable
main()
{
Person person1("Bayo","Lawal",1,"April",89,"lagos");
person1.display();
}/////END OF FIRST CODE
/////BEGINNING OF SECOND SET OF CODES
|