Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

CLASSES AND OBJECTS:

1
#include<iostream>

using namespace std;

int main()

cout<<"name=Mehreen"<<endl;

cout<<"branch=sialkot"<<endl;

cout<<"year=2020"<<endl;

2
#include<iostream>

using namespace std;

int main()

char opt;

int x,y,res;

int q;

cout<<"Enter 2 values:";

cout<<"+Addition\n-:subtraction\n*:multiplication\n/:division";

switch (opt)

{
case'+':res=x+y;

cout<<"Addition is =",res;

break;

case'-':res=x-y;

cout<<"subtraction is =",res;

break;

case'*':res=x*y;

cout<<"multiplication is =",res;

break;

case'/':if(y==0)

cout<<"division is =",res;

else

cout<<"qoutient is %f",q;

default:

cout<<"invalid number";

}}

6
#include <iostream>

using namespace std;


class StudentClass

private:

char name[20],branch[10];

int semester,marks of eng,maths,phy,che,comp,bio;

float total, avg;

public:

void read()

cout << "Enter Name :";

cin >> name;

cout << "Enter branch :";

cin >> branch;

cout << "Enter semester :";

cin >> semester;

cout << "Enter Marks for eng,maths,phy,che,comp,bio:";

cin >> eng>>maths>>phy>>che>>comp>>bio;

void sum()

total = eng+maths+phy+che+comp+bio;

avg = total / 6;

}
void print() {

cout << "Name :" << name << endl;

cout << "branch :" << branch << endl;

cout << "semester :" << semester << endl;

cout << "Marks :" << eng << " , " << maths << " , " << phy<<
che<<","<<comp<<","<<bio<<","<<endl;

cout << "Total :" << total << endl;

cout << "Average :" << avg << endl;

}};

int main()

StudentClass stu;

cout << "display marks sheet of studen\n";

cout << "\nStudentClass : Student " << endl;

stu.read();

stu.sum();

stu.print();

7
#include<iostream>

using namespace std;

class employee
{

char emp_name[20];

float emp_age;

public:

void get_details();

void show_emp_details();

};

void employee :: get_details()

cout<<"\nEnter employee name:\n"<<endl;

cin>>emp_name;

cout<<"\nEnter employee age:\n"<<endl;

cin>>emp_age;

};

void employee :: show_emp_details()

cout<<"\n\n\nDetails of : "<<emp_name<<endl;

cout<<"\n\nEmployee age: "<<emp_age<<endl;

int main()

employee emp[10];

int i,num;
{

cout<<"\nEnter number of employee details\n";

cin>>num;

for(i=0;i<num;i++)

emp[i].get_details();

for(i=0;i<num;i++)

emp[i].show_emp_details();

return 0;

8
#include<iostream>

using namespace std;

class bank

char name[20];

int ano;

char atype[20];

float bal;

public:

void get(int no,char *n,char *t,float b)


{

(name,n);

ano=no;

(atype,t);

bal=b;

float deposit()

float amt;

cout<<"\nEnter amount:";

cin>>amt;

bal=bal+amt;

return bal;

float withdrw()

float amt;

cout<<"\nHow many Rupees withdraw: ";

cin>>amt;

bal=bal-amt;

return bal;

void disp()
{

cout<<"\n\nAccount number:" <<ano;

cout<<"\n\nName: "<<name;

cout<<"\n\nAccount type: "<<atype;

cout<<"\n\nDeposit Amount: "<<deposit();

cout<<"\n\nAfter Withdraw Amount balnace: "<<withdrw();

};

void main()

int n;

char nm[20],t[20];

float a;

bank bk;

cout<<"\nEnter Account no.:" ; cin>>n;

cout<<"\nEnter Name: "; cin>>nm;

cout<<"\nEnter account type: "; cin>>t;

cout<<"\nEnter balance amount: ";cin>>a;

bk.get(n,nm,t,a);

bk.disp();

9
#include<iostream>
using namespace std;

class emp

float emp_code,dep_code,age,basic,DA,HRA;

char name[20],num[10];

public:

void getdata();

void putdata();

void caldata();

};

void emp::getdata()

cout<<"\nEnter employee number:";

cin>>name;

cout<<"Enter employee name:";

cin>>num;

cout<<"Enter employee basic salary in Rs: " ;

cin>>basic;

void emp::putdata()

DA=((0.52)*basic );

float gsal=DA+basic;
HRA=((0.3)*gsal);

void emp::caldata()

cout<<"\nEmployee number:"<<name;

cout<<"\nEmployee name:"<<num;

int main()

int n;

cout<<"\nCalculation of 10 Employee Net Salary";

cout<<"\n Enter the number of employees";

cin>>n;

for(int i=0;i<n;i++)

void getdata();

void putdata();

cout<<"\nEmployee Detail:";

cout<<"\n\n Employee:";

void caldata();

You might also like