Professional Documents
Culture Documents
#include<iostream>
class Rectangle
protected:
public:
void set_width(int w)
width = w;
void set_height(int h)
height = h;
int get_area()
int get_perimeter()
}
};
public:
int length;
Square()
Square(int length){
set_width(length);
set_height(length);
};
public:
int depth;
Cube()
{}
int volume()
int get_surfaceArea()
{
};
int main()
Rectangle a1;
Rectangle p1;
cin>>width;
p1.set_width(width);
cin>>height;
p1.set_height(height);
cout<<endl;
cin>>width;
a1.set_width(width);
cin>>height;
a1.set_height(height);
cout<<endl;
cin>>length;
Square s1(length);
cout<<endl;
Cube c1(length);
cout<<endl;
cout<<"\t\t\t\t==========********=========="<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
return 0;
}
Output:
#include<iostream>
#include<string.h>
class Person
protected:
string name;
string Address;
string CNIC;
string CellNo;
public:
Person()
Person(string n, string a, string cnic, string cell) : name(n), Address(a), CNIC(cnic), CellNo(cell)
~Person()
count--;
void set_name(string n)
name = n;
void set_Address(string a)
Address = a;
CNIC = cnic;
CellNo = cell;
string get_name()
{
return name;
string get_Address()
return Address;
string get_CNIC()
return CNIC;
string get_CellNo()
return CellNo;
};
public:
string TeacherID;
Teacher()
count++;
TeacherID = teacher;
~Teacher()
count--;
TeacherID = teacher;
string get_TeacherID()
return TeacherID;
void print()
{
cout<<"NAME:"<<name<<endl;
cout<<"ADDRESS:"<<Address<<endl;
cout<<"CNIC"<<CNIC<<endl;
cout<<"CELL NUMBER:"<<CellNo<<endl;
cout<<"TEACHER ID:"<<TeacherID<<endl;
};
public:
string StudentID;
Student()
count++;
StudentID = student;
~Student()
count--;
StudentID = student;
}
string get_StudentID()
return StudentID;
cout<<count<<endl;
void print()
cout<<"NAME:"<<name<<endl;
cout<<"ADDRESS:"<<Address<<endl;
cout<<"CNIC:"<<CNIC<<endl;
cout<<"CELL NUMBER:"<<CellNo<<endl;
cout<<"STUDENT ID:"<<StudentID<<endl;
};
int main()
Person p2("John", "123 Main St", "123456789", "123-456-7890");// 2nd Object for Person Class with
Parameterized Constructor(PP)
Teacher t2("Alice", "456 Elm St", "987654321", "987-654-3210", "T123");// 2nd Object for Teacher
Class with Parameterized Constructor(PP)
Student s2("Bob", "789 Oak St", "543216789", "543-216-7890", "S456");// 2nd Object for Student
Class with Parameterized Constructor(PP)
cout<<"Teacher's Details:"<<endl;
t2.print();
cout<<endl;
cout<<"Student's Details:"<<endl;
s2.print();
p1.set_name("Faiza");
p1.set_CNIC("198-231-4526");
p1.set_CellNo("550383632");
// Using accessors to update the info in data members for Student
t1.set_name("Ali");
t1.set_CNIC("218-221-7865");
t1.set_CellNo("321564789");
t1.set_TeacherID("901233");
s1.set_name("Timothee");
s1.set_CNIC("102-541-0987");
s1.set_CellNo("8970274921");
s1.set_StudentID("221000");
cout<<endl;
cout<<"Name:"<<p1.get_name()<<endl;
cout<<"CNIC:"<<p1.get_CNIC()<<endl;
cout<<"Address:"<<p1.get_Address()<<endl;
cout<<"Cell Number:"<<p1.get_CellNo()<<endl;
cout<<endl;
cout<<"Name:"<<t1.get_name()<<endl;
cout<<"CNIC:"<<t1.get_CNIC()<<endl;
cout<<"Address:"<<t1.get_Address()<<endl;
cout<<"Cell Number:"<<t1.get_CellNo()<<endl;
cout<<"Teacher's ID:"<<t1.get_TeacherID()<<endl;
cout<<endl;
cout<<"Name:"<<s1.get_name()<<endl;
cout<<"CNIC"<<s1.get_CNIC()<<endl;
cout<<"Address:"<<s1.get_Address()<<endl;
cout<<"Cell Number:"<<s1.get_CellNo()<<endl;
cout<<"Student's ID:"<<s1.get_StudentID()<<endl;
return 0;
}
Output: