0% found this document useful (0 votes)
19 views

Assignment 3

The document defines classes for person, student, and foreign student with getters and setters. It then takes user input to create objects of these classes and outputs data for foreign students from Turkey in section A who are male.

Uploaded by

Xoha Fatima
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Assignment 3

The document defines classes for person, student, and foreign student with getters and setters. It then takes user input to create objects of these classes and outputs data for foreign students from Turkey in section A who are male.

Uploaded by

Xoha Fatima
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Assignment 3

Object oriented programming


Submitted to Sir Adrees
By: Zoha Fatima
ID: F2022463002

Task 1

#include<iostream>
using namespace std;
class person{
int id;
string name;
int age;
public:
//setters
void setid()
{
cout<<"Enter your ID:";
cin>>id;
}
void setname()
{
cout<<"Enter your name:";
cin>>name;

void setage()
{
cout<<"Enter your Age:";
cin>>age;
}
//gettersssss
void showid() const
{
cout<<"Entered ID is: "<<id<<endl;
}
void showname() const
{
cout<<" Entered Name is:"<<name<<endl;
}
void showage() const
{
cout<<" Entered Age is:"<<age<<endl;
}
person ()
{
setid();
setname();
setage();

}
};

class student :public person


{
string course_name;
string section;
string gender;
public:
//setters
void setgender(){
cout<<"Enter your Gender:";
cin>>gender;
}
void setcourse_name()
{
cout<<"Enter your Course name:";
cin>>course_name;

void setsection()
{
cout<<"Enter your Section:";
cin>>section;
}
//gettersssss
string getsection()
{
return section;
}
string getgender()
{
return gender;
}
void showgender()const{
cout<<"Entred Gender is:"<<gender<<endl;
}
void showcourse_name() const
{
cout<<"Entered Course Name is: "<<course_name<<endl;
}
void showsection() const
{
cout<<" Entered Section is:"<<section<<endl;
}

student ()
{
setsection();
setcourse_name();
setgender();

}
};
class foreign_student: public student{
string country;
string passport_no;
string visa_issue;
string visa_expire;
public:
//setters
void setcountry()
{
cout<<"Enter your Country Name:";
cin>>country;
}
void setpassport_no()
{
cout<<"Enter your Passport No:";
cin>>passport_no;

void setvisa_issue()
{
cout<<"Enter your Visa Issue Date:";
cin>>visa_issue;
}
void setvisa_expire()
{
cout<<"Enter your Visa Issue Date:";
cin>>visa_expire;
}
//gettersssss
string getcountry ()
{
return country;
}
void showcountry() const
{
cout<<"Entered Country Name is: "<<country<<endl;
}
void showpassport_no() const
{
cout<<" Entered Passport Number is:"<<passport_no<<endl;
}
void showvisa_issue() const
{
cout<<" Entered Visa Issue Date is:"<<visa_issue<<endl;
}
void showvisa_expire() const
{
cout<<" Entered Visa Expire Date is:"<<visa_expire<<endl;
}
foreign_student ()
{
setcountry();
setpassport_no();
setvisa_issue();
setvisa_expire();

}
};
int main()
{
char a;
cout<<"Enter 'p' for enter Person,s Data. "<<endl;
cout<<"Enter 's' for enter Student,s Data."<<endl;
cout<<"Enter 'f' for enter Foreign Student,s Data."<<endl;
cin>>a;
switch (a)
{
case 'p':
{
person q;
break;
}

case 's':{

student q;
break;
}

case 'f':{
foreign_student q;
break;
}

default:
cout<<"Invalid Entry";
}
cout<<"Enter 50 Foreign Students Data...."<<endl;
foreign_student q[50];
cout<<"Data of those Foreign Students who are From Turkey,Section 'A' and are Male... "<<endl;
string d,b,c;
for(int i=0;i<50;i++){
d=q[i].getsection();
b=q[i].getcountry();
c=q[i].getgender();
if(c=="m" && b=="turkey" && d=="A")
{

cout<<"Entry no: "<<i+1<<endl;


q[i].showid();
q[i].showname();
q[i].showage();
q[i].showsection();
q[i].showcourse_name();
q[i].showgender();
q[i].showcountry();
q[i].showpassport_no();
q[i].showvisa_issue();
q[i].showvisa_expire();
}
}
return 0;
}

Task 2

#include<iostream>
using namespace std;
class person{
int id;
string name;
int age;
public:
//setters
void setid()
{
cout<<"Enter your ID:";
cin>>id;
}
void setname()
{
cout<<"Enter your name:";
cin>>name;

}
void setage()
{
cout<<"Enter your Age:";
cin>>age;
}
//gettersssss
void showid() const
{
cout<<"Entered ID is: "<<id<<endl;
}
void showname() const
{
cout<<" Entered Name is:"<<name<<endl;
}
void showage() const
{
cout<<" Entered Age is:"<<age<<endl;
}
person ()
{
setid();
setname();
setage();

}
};

class student
{
string course_name;
string section;
string gender;
public:
//setters
void setgender(){
cout<<"Enter your Gender:";
cin>>gender;
}
void setcourse_name()
{
cout<<"Enter your Course name:";
cin>>course_name;

void setsection()
{
cout<<"Enter your Section:";
cin>>section;
}
//gettersssss
string getsection()
{
return section;
}
string getgender()
{
return gender;
}
void showgender()const{
cout<<"Entred Gender is:"<<gender<<endl;
}
void showcourse_name() const
{
cout<<"Entered Course Name is: "<<course_name<<endl;
}
void showsection() const
{
cout<<" Entered Section is:"<<section<<endl;
}

student ()
{
setsection();
setcourse_name();
setgender();

}
};
class foreign_student: public person, public student{
string country;
string passport_no;
string visa_issue;
string visa_expire;
public:
//setters
void setcountry()
{
cout<<"Enter your Country Name:";
cin>>country;
}
void setpassport_no()
{
cout<<"Enter your Passport No:";
cin>>passport_no;

void setvisa_issue()
{
cout<<"Enter your Visa Issue Date:";
cin>>visa_issue;
}
void setvisa_expire()
{
cout<<"Enter your Visa Issue Date:";
cin>>visa_expire;
}
//gettersssss
string getcountry ()
{
return country;
}
void showcountry() const
{
cout<<"Entered Country Name is: "<<country<<endl;
}
void showpassport_no() const
{
cout<<" Entered Passport Number is:"<<passport_no<<endl;
}
void showvisa_issue() const
{
cout<<" Entered Visa Issue Date is:"<<visa_issue<<endl;
}
void showvisa_expire() const
{
cout<<" Entered Visa Expire Date is:"<<visa_expire<<endl;
}
foreign_student ()
{
setcountry();
setpassport_no();
setvisa_issue();
setvisa_expire();

}
};
int main()
{
char a;
cout<<"Enter 'p' for enter Person,s Data. "<<endl;
cout<<"Enter 's' for enter Student,s Data."<<endl;
cout<<"Enter 'f' for enter Foreign Student,s Data."<<endl;
cin>>a;
switch (a)
{
case 'p':
{
person q;
break;
}

case 's':{

student q;
break;
}

case 'f':{
foreign_student q;
break;
}

default:
cout<<"Invalid Entry";
}
cout<<"Enter 50 Foreign Students Data...."<<endl;
foreign_student q[50];
cout<<"Data of those Foreign Students who are From Turkey,Section 'A' and are Male... "<<endl;
string d,b,c;
for(int i=0;i<50;i++){
d=q[i].getsection();
b=q[i].getcountry();
c=q[i].getgender();
if(c=="m" && b=="turkey" && d=="A")
{

cout<<"Entry no: "<<i+1<<endl;


q[i].showid();
q[i].showname();
q[i].showage();
q[i].showsection();
q[i].showcourse_name();
q[i].showgender();
q[i].showcountry();
q[i].showpassport_no();
q[i].showvisa_issue();
q[i].showvisa_expire();
}
}
return 0;
}

You might also like