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

OOp Assignment 1

This document contains code for an object-oriented C++ program that defines classes to represent student and employee data. The student classes - student, studentgrade, and studentgpa - define attributes and methods to set and get a student's ID, name, address, phone number, grade, and GPA. The main function demonstrates creating a student object and collecting user input to populate the attributes. The employee classes - Employee and Salary - define attributes and methods to set and get an employee's name, ID, address, phone number, monthly income, and leave days. The main function demonstrates creating an employee object, collecting user input, and calculating income deductions based on leave days.

Uploaded by

Zeeshan Jutt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

OOp Assignment 1

This document contains code for an object-oriented C++ program that defines classes to represent student and employee data. The student classes - student, studentgrade, and studentgpa - define attributes and methods to set and get a student's ID, name, address, phone number, grade, and GPA. The main function demonstrates creating a student object and collecting user input to populate the attributes. The employee classes - Employee and Salary - define attributes and methods to set and get an employee's name, ID, address, phone number, monthly income, and leave days. The main function demonstrates creating an employee object, collecting user input, and calculating income deductions based on leave days.

Uploaded by

Zeeshan Jutt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Superior University Gold Campus

Object oriented Programming

Department
Information Technology

Submitted To
Sir Ahmad Amin

Submitted By
Zeeshan Basharat

Roll no.
BITM-F21-070

Question # 2:
#include<iostream>
using namespace std;
class student {
protected:
string ID;
string name;
string address;
string phone_no;
public:
student()
{
this->ID = "";
this->name = "";
this->address = "";
this->phone_no = "";
}
void setID(string id) {
this->ID = id;
}
void setname(string name) {
this->name = name;
}
void setaddress(string address) {
this->address = address;
}
void setphone_no(string phone)
{
this->phone_no = phone;
}
string getID() {
return this->ID;
}
string getname() {
return this->name;
}
string getaddress() {
return this->address;
}
string getphone_no()
{
return this->phone_no;
}
};

class studentgrade : public student {


protected:
string grade;
public:
void setgrade(double gpa)
{
if (gpa == 4.00)
{
grade = "A";
}
if ( gpa< 4.0&& gpa >= 3.66)
{
grade = "A-";
}
if ( gpa< 3.66 && gpa >= 3.33)
{
grade = "B+";
}
if ( gpa < 3.33 && gpa >=3.00)
{
grade = "B";
}
if ( gpa<3.00 && gpa >= 2.66)
{
grade = "B-";
}
if ( gpa< 2.66 && gpa >= 2.33)
{
grade = "C+";
}
if ( gpa< 2.33 && gpa >= 2.00)
{
grade = "C";
}
if ( gpa< 2.0 && gpa >= 1.66)
{
grade = "C-";
}
if (gpa< 1.66 && gpa >= 1.30)
{
grade = "D+";
}
if (gpa<1.30 && gpa >= 1.00)
{
grade = "D";
}
if (gpa< 1.0 && gpa >= 0.00)
{
grade = "F";
}
}
string getgrade()
{
return this->grade;
}
};
class studentgpa: public studentgrade{
protected:
double gpa;
public:
void setgpa(double perc)
{
if (perc > 85)
{
gpa=4.00;
}
if ( perc< 85 && perc >= 80)
{
gpa=3.66;
}
if (perc<80 && perc >= 75)
{
gpa=3.33;
}
if ( perc< 75 && perc >= 71)
{
gpa=3.00;
}
if (perc<71 && perc >=68)
{
gpa=2.66;
}
if (perc<68 && perc >= 64)
{
gpa=2.33;
}
if (perc< 64 && perc >= 61)
{
gpa=2.00;
}
if (perc<61 && perc >= 58)
{
gpa=1.66;
}
if (perc<58 && perc >= 54)
{
gpa=1.30;
}
if (perc<54 && perc >= 50)
{
gpa=1.00;
}
if (perc<50 && perc >= 0)
{
gpa=0.00;
}
}
double getgpa()
{
return this->gpa;
}
};
int main()
{
studentgpa s1;
string name, address, id;
string phone_number;
int marks;
double perc,gpa;

cout << "ENTER DATA OF STUDENT :" << endl;


cout << "Enter The Student Id: ";
cin >> id;
s1.setID(id);
cout << "Enter The Student Name: ";
cin >> name;
s1.setname(name);
cout << "Enter The Student Address: ";
cin >> address;
s1.setaddress(address);
cout << "Enter The Student Phone Number: ";
cin >> phone_number;
s1.setphone_no(phone_number);
cout << "Enter The Student Marks from 100: ";
cin >> marks;
perc=(marks/100)*100;
s1.setgpa(perc);
gpa=s1.getgpa();
s1.setgrade(gpa);
cout << endl;

cout << "Student Id: "<<s1.getID()<<endl;

cout << "Student Name: "<<s1.getname()<<endl;

cout << "Student Address: "<<s1.getaddress()<<endl;

cout << "Student Phone Number: "<<s1.getphone_no()<<endl;

cout << "Student gpa: "<<s1.getgpa()<<endl;

cout << "Student Grade: "<<s1.getgrade()<<endl;

return 0;

}
Question # 1:

#include<iostream>
using namespace std;
class Employee
{
string employee_name;
int employee_id;
string employee_address;
double employee_phone_No;
public:
void setemployee_name(string a) {
this->employee_name=a;
}
string getemployee_name() {
return this->employee_name;
}
void setemployee_id(int b) {
this->employee_id=b;
}
int getemployee_id(){
return this->employee_id;
}
void setemployee_address(string c) {
this->employee_address=c;
}
string getemployee_address(){
return this->employee_address; }
void setemployee_phone_No(double d){
this->employee_phone_No=d;
}
double getemployee_phone_No(){
return this->employee_phone_No;
}
};
class Salary
{
int employee_leave;
double employee_monthly_income;
public:
void input();
void disp();
};
void Salary::input()
{
cout<<"Enter the Monthly Income:";
cin>>employee_monthly_income;
}
void Salary::disp()
{
for(int i=1;i<=5;i++)
{
cout<<"Enter the days Employee is on leave:"<<endl;
cin>>employee_leave;
if(employee_leave>=1)
{
cout<<"Enter the detuction % the Employee is on leave:"<<endl;
cout<<"Your Monthly income after detuction is = "<<employee_monthly_income-
((employee_monthly_income*5 /100))<<endl;
}
else if(employee_leave==0)
{
cout<<"Your Monthly income = "<<employee_monthly_income<<endl;
}}}
int main()
{
string name;
int id;
string address;
double phone_No;
Employee obj;
cout<<"Enter the Name of Employee:";
cin>>name;
obj.setemployee_name(name);
cout<<"Enter the Id of Employee:";
cin>>id;
obj.setemployee_id(id);
cout<<"Enter the Address of Employee:";
cin>>address;
obj.setemployee_address(address);
cout<<"Enter the phone no of Employee:";
cin>>phone_No;
obj.setemployee_phone_No(phone_No);
cout<<"The name of Employee="<<obj.getemployee_name()<<endl;
cout<<"The id of Employee="<<obj.getemployee_id()<<endl;
cout<<"The adress of Employee="<<obj.getemployee_address()<<endl;
cout<<"The phone no of Employee ="<<obj.getemployee_phone_No()<<endl;
Salary obj1;
obj1.input();
obj1.disp();
}

You might also like