Assignment 3 Without Output
Assignment 3 Without Output
Assignment 3 Without Output
#include <iostream>
class Date {
private:
int day;
int month;
int year;
public:
};
class Employee {
private:
Date dateOfJoining;
Date dateOfBirth;
public:
Employee(int dojDay, int dojMonth, int dojYear, int dobDay, int dobMonth, int dobYear)
return dateOfJoining.withinLastFiveYears(currentYear);
return dateOfBirth.ageLessThan40(currentYear);
};
class Base {
public:
};
public:
void iam() {
};
public:
void iam() {
};
int main() {
cout << "Employee one joined within last five years: "
cout << "Employee one has age less than 40: "
cout << "Employee two joined within last five years: "
cout << "Employee two has age less than 40: "
Base* basePtr;
Base baseObj;
Derived1 derived1Obj;
Derived2 derived2Obj;
basePtr = &baseObj;
basePtr->iam();
basePtr = &derived1Obj;
basePtr->iam();
basePtr = &derived2Obj;
basePtr->iam();
return 0;
Output:
#include <iostream>
class Shape
protected:
public:
};
public:
void get_data() {
cout << "Enter base and height of triangle: ";
void display_area() {
cout << "Area of Triangle is: " << 0.5 * dim1 * dim2 << endl;
{ public:
void get_data() {
void display_area() {
cout << "Area of Rectangle is: " << dim1 * dim2 << endl;
};int main() {
Triangle t;
t.get_data();
t.display_area();
Rectangle r;
r.get_data();
r.display_area();
Output:
#include <iostream>
#include <cstring>
class Address {
private:
char* street;
char* house;
char* city;
char* code;
public:
setStreet(s);
setHouse(h);
setCity(c);
setCode(cd);
}
~Address() {
delete[] street;
delete[] house;
delete[] city;
delete[] code;
return street;
delete[] street;
strcpy(street, s);
return house;
delete[] house;
strcpy(house, h);
return city;
delete[] city;
city = new char[strlen(c) + 1];
strcpy(city, c);
return code;
delete[] code;
strcpy(code, cd);
};
class Person {
private:
Address address;
public:
return address;
address = a;
};
int main() {
Person person(address);
person.setAddress(newAddress);
return 0;
Output:
#include <iostream>
#include <string>
class Teacher {
protected:
string teacherName;
int age;
string address;
public:
Teacher() {
~Teacher() {
void inputTeacher() {
getline(cin, teacherName);
getline(cin, address);
void displayTeacher() {
};class Author {
protected:
string authorName;
string address;
int numOfBooks;
public:
Author() {
}void inputAuthor() {
getline(cin, authorName);
getline(cin, address);
}void displayAuthor() {
cout << "Number of Books Written: " << numOfBooks << endl;
public:
Scholar() {
} ~Scholar() {
}void inputScholar() {
inputTeacher();
inputAuthor();
}void displayScholar() {
displayTeacher();
displayAuthor();
};int main() {
Scholar scholar;
scholar.inputScholar();
scholar.displayScholar(); return 0;
Output:
#include <iostream>
#include <string>
class Teacher {
protected:
string teacherName;
int age;
string address;
public:
void inputTeacher() {
getline(cin, teacherName);
void displayTeacher() {
};
class Author {
protected:
string authorName;
string address;
int numOfBooks;
public:
void inputAuthor() {
getline(cin, authorName);
getline(cin, address);
} void displayAuthor() {
cout << "Number of Books Written: " << numOfBooks << endl;
};
class Scholar : public Teacher, public Author {
public:
void inputScholar() {
inputTeacher();
inputAuthor();
void displayScholar() {
displayTeacher();
displayAuthor();
};int main() {
Scholar scholar;
scholar.inputScholar();
scholar.displayScholar();
return 0;
Output:
#include <iostream>
#include <string>
class DateTime {
private:
int day;
int month;
int year;
int hour;
int minute;
int second;public:
day = d;
month = m;
year = y;
hour = h;
minute = min;
second = sec;
} void displayDateTime() {
cout << "Date: " << day << "/" << month << "/" << year << endl;
cout << "Time: " << hour << ":" << minute << ":" << second << endl;
};int main() {
Watch.displayDateTime();
Watch.displayDateTime();
return 0;
Output:
#include <iostream>
#include <string>
class Person {
protected:
string name;
int age;
string gender;
public:
this->name = name;
this->age = age;
this->gender = gender;
}string getName() {
return name;
}string getGender() {
return gender;
};class Employee {
protected:
string employerName;
double dailyWages;public:
this->employerName = employerName;
this->dailyWages = dailyWages;
}string getEmployerName() {
return employerName;
}double getDailyWages() {
return dailyWages;
private:
string grade;
public:
this->grade = grade;
};int main() {
Teacher teacher;
teacher.setName("NOUMAN");
teacher.setAge(20);
teacher.setGender("Male");
teacher.setEmployerName("aps School");
teacher.setDailyWages(99.9);
return 0;
}
Output:
#include <iostream>
class Base {
protected:
int baseData1;
int baseData2;
public:
baseData1 = data1;
baseData2 = data2;
} void displayBaseData() {
int derivedData;
public:
derivedData = data;
} void displayDerivedData() {
public:
void accessBaseAndDerived1() {
displayBaseData();
displayDerivedData();
};int main() {
Derived2 obj;
obj.setBaseData(10, 20);
obj.setDerivedData(30);
obj.accessBaseAndDerived1();
return 0;
Output:
#include <iostream>
class Person {
int id;
string name;
string addr;
public :
void getdata() {
getline(cin,addr);
void showdta(){
cout<<"\nID No.: "<<id;
cout<<"\nName: "<<name;
cout<<"\nAddress: "<<addr;
float m1,m2,m3;
public :
void getdata() {
Person ::getdata();
cin>>rno;
cin>>m1>>m2>>m3;
void showdata(){
Person::showdata();
cout<<endl<<"RollNo:"<<rno;
<<"Subject-1="<<m1
int main()
Student s;
s.getdata();
s.showdata();
return 0;
Output:
#include <iostream>
#include <string>
class publication {
protected:
std::string title;
float price;
public:
// Default constructor
publication() {
title = "";
price = 0.0;
void getdata() {
};
private:
int page_count;
public:
// Default constructor
book() : publication() {
page_count = 0;
void getdata() {
publication::getdata();
publication::putdata();
};
private:
float playing_time;
public:
// Default constructor
tape() : publication() {
playing_time = 0.0;
void getdata() {
publication::getdata();
publication::putdata();
std::cout << "Playing Time: " << playing_time << " minutes" << std::endl;
};int main() {
book b;
tape t;
b.getdata();
b.putdata();
t.putdata();
return 0;
Output:
#include <iostream>
class Computer {
protected:
int wordsize;
int memorysize;
int storagesize;
int speed;
public:
// Default constructor
Computer() {
wordsize = 0;
memorysize = 0;
storagesize = 0;
speed = 0;
this->wordsize = wordsize;
this->memorysize = memorysize;
this->storagesize = storagesize;
this->speed = speed;
void display() {
std::cout << "Word Size: " << wordsize << " bits\n";
std::cout << "Memory Size: " << memorysize << " megabytes\n";
std::cout << "Storage Size: " << storagesize << " megabytes\n";
private:
int length;
int width;
int height;
int weight;
public:
// Default constructor
Laptop() : Computer() {
length = 0;
width = 0;
height = 0;
weight = 0;
Laptop(int wordsize, int memorysize, int storagesize, int speed, int length, int width, int height, int weight)
this->length = length;
this->width = width;
this->height = height;
this->weight = weight;
void display() {
Computer::display();
};int main() {
computer.display();
laptop.display();
return 0;
Output: