Menu

Saturday, 3 August 2013

Chapter 6,Problem 6:Object Oriented Programming by Robert Lafore in C++ Solution Manual

//Engr. Ahmad Furqan Attari
//Chapter 6, Problem 6
#include <iostream>
#include <conio.h>
using namespace std;
enum etype{laborer, secretary , manager };
class date
{
private:
int day,month,year;
public:
void getdate(void)
{
char ch;
cin>>month>>ch>>day>>ch>>year;
}
void showdate(void)
{
cout<<month<<"/"<<day<<"/"<<year;
}
};
class employee
{
private:
int e_num;
float salary;
date join_date;
etype type;
public:
void enter_data(void)
{
cout<<"Enter employee number: ";
cin>>e_num;
cout<<"Enter employee's salary: ";
cin>>salary;
cout<<"Enter employee's date of joining (mm/dd/yyyy): ";
join_date.getdate();
cout<<"Enter employee's type (1.laborer; 2.secretary; 3.manager): ";
switch(getch())
{
case '1':
type=laborer;break;
case '2':
type=secretary;break;
case '3':
type=manager;break;
}
cout<<endl;
}
void display(void)
{
cout<<"Employee number: "<<e_num<<endl;
cout<<"Employee salary: "<<salary<<endl;
cout<<"Employee joining date :";
join_date.showdate();
cout<<endl<<"Employee type: ";
switch(type)
{
case laborer:
cout<<"Laborer"<<endl;break;
case secretary:
cout<<"Secretary"<<endl;break;
case manager:
cout<<"Manager"<<endl;break;
}
}
};
void main(void)
{
employee emp1,emp2,emp3;
cout<<"Enter data for employee 1 "<<endl;
emp1.enter_data();
cout<<"Enter data for employee 2 "<<endl;
emp2.enter_data();
cout<<"Enter data for employee 3 "<<endl;
emp3.enter_data();
cout<<"The entered data is "<<endl;
emp1.display();
cout<<endl;
emp2.display();
cout<<endl;
emp3.display();
getch();
}

2 comments:

  1. #include
    using namespace std;
    class a
    {
    int nomirator;
    int denomirator;
    public:
    a()
    {
    nomirator = 0;
    denomirator = 0;
    }

    void get()
    {
    cout << "enter nomirator :"; cin >> nomirator;
    cout << "enter deonmirator :"; cin >> denomirator;
    }
    void add(a obj1)
    {
    float a, b;
    a = (obj1.nomirator*denomirator) + (nomirator*obj1.denomirator);
    b = obj1.denomirator * denomirator;
    cout << "the addiition of two fraction " << a << " /" << b << endl;
    }
    };
    int main()
    {
    a obj1[10], obj2[10], obj3[10];
    char n;
    cout << "do you want to use programme enter y :"; cin >> n;
    //int i = 0;
    for (int i = 0; n == 'y'; i++)
    {

    obj1[i].get();
    obj2[i].get();
    obj3[i] = obj1[i], obj3[i].add(obj2[i]);
    //i++;
    cout << "do you want to use programme :"; cin >> n;
    }

    system("pause");
    }

    ReplyDelete
  2. q8::
    #include
    using namespace std;
    class a
    {
    static int seralno;
    static int count;
    public:
    a()
    {
    seralno++;
    cout << "seral no is :" << seralno << endl;
    count++;
    }

    void display()const
    {

    cout << "total count is " <<count<< endl;
    }
    };
    int a::count(0);
    int a::seralno(0);
    int main()
    {
    a obj1, obj2, obj3, obj4;
    obj1.display();
    system("pause");
    }

    ReplyDelete