slip 1

/Slip no : 1 Write a C++ program to create a class Worker with data members as Worker_Name, No_of_Hours_worked, Pay_Rate. Write necessary member functions to calculate and display the salary of worker. (Use default value for Pay_Rate)           */

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
class worker
{
                char name[10];
                int hr;
                public:
                void accept()
                {             
                                cout<<"enter name";
                                cin>>name;
                                cout<<"enter hours";
                                cin>>hr;
                }

                void calculate(int rate=50)
                {
                                cout<<"salary of worker is Rs."<<(hr*30)*rate;
                }
};

void main()
{
                worker ob;
                clrscr();
                ob.accept();
                ob.calculate();
                getch();

}




/* slip 1_2 Create class Person which contains data member as Passport_Id,
Person_name,Nationality,  Gender, Date_of_Birth, Date_of_Issue,
Date_of_expiry .
Write a c++ program to perform following member functions:
Enter details of all persons
Display passport details of one person
Display passport details of  all persons
(Use Function overloading and Array of object).*/


#include<conio.h>
#include<iostream.h>
class Person
{
int id;
char name[10],gender[5],nationality[10];
char dob[10],issue[10],exp[10];
public:
void accept()
{
cout<<"Enter id ";
cin>>id;
cout<<"Enter name ";
cin>>name;
cout<<"Enter date of birth ";
cin>>dob;
cout<<"Enter gender ";
cin>>gender;
cout<<"Enter date of issue ";
cin>>issue;
cout<<"Enter date of expiry ";
cin>>exp;
cout<<"Enter nationality ";
cin>>nationality;
}

void display()
{
cout<<"Id = "<<id<<endl<<"Name = "<<name<<endl<<"Gender = "<<gender<<endl<<"DOB = "<<dob;
cout<<"Issue Date = "<<issue<<endl<<"Expiry Date = "<<exp<<endl<<"Nationality = "<<nationality;
cout<<endl;
}

int display(int pid)
{
if(id==pid)
{
display();
return 1;
}
else return 0;
}

};

void main()
{
Person ob[10];
int id,i,n;
clrscr();
cout<<"\n Enter how many person ";
cin>>n;
cout<<"\n Enter information "<<endl;
for(i=0;i<n;i++)
{
ob[i].accept();
}
cout<<"\n Detials of all person ";
cout<<"\n ============================ \n";
for(i=0;i<n;i++)
{
ob[i].display();
}

cout<<"\n Enter id to search ";
cin>>id;
int ans,cnt=0;
for(i=0;i<n;i++)
{
ans=ob[i].display(id);
if(ans==1)
cnt++;
}
if(cnt==0)
cout<<"id is not found...";
getch();

}
slip 1  slip 1 Reviewed by Dinesh Varal on January 13, 2018 Rating: 5

No comments:

Powered by Blogger.