You are on page 1of 4

(SAHIWAL CAMPUS)

COURSE TITLE : OOP LAB


ASSIGNMENT NO : 03
SUBMITTED TO : Sir Fayez Afzaal
SUBMITTED BY: Rana Mudassir Ali
ROLL NUMBER: SP22-BCS-102
SECTION : C
DATE OF SUBMISSION :
Solution of Assignment:
Input (code) Q1:
#include <iostream>
#include<conio.h>
using namespace std;
class tollbooth
{
private:
    unsigned int T_NoCar;
    double T_Cash;
public:
    tollbooth():T_Cash(0), T_NoCar(0.0){}

    void PayingCar(){
        T_NoCar++;
        T_Cash+=0.50;
    }
    void NoPayingCar(){
        T_NoCar++;
    }
void display() const{
    cout<<endl<<endl<<"***....Display Info....***"<<endl<<endl;
   cout<<" Total Car passed: "<<T_NoCar<<endl;
   cout<<" Total money collected: $"<<T_Cash<<endl;}};
int main()
{
    tollbooth obj;
    char key;
    cout<<"  ***....Main Menu....***"<<endl<<endl;
    while(true){
        cout<<" Enter 'P' for paying car 'N' for nonpaying and 'Esc' for exit: ";
        key=getch();
       if(key=='P'|| key=='p'){
        obj.PayingCar();
        cout<<" **..paying car..**"<<endl; }
       else if(key=='N'|| key=='n'){
        obj.NoPayingCar();
        cout<<" **..Non-paying car..**"<<endl;}
       else if(key==27){
        obj.display();
        break; }
        else {cout<<"Invalid Entery"<<endl; }
    return 0;
}

Output:
Input (code) Q2:
#include<iostream>
using namespace std;
class time{
    private:
    int hour,minutes,seconds;
    public:
    time():hour(0),minutes(0),seconds(0){}
    time(int hr,int min,int sec):hour(hr),minutes(min),seconds(sec){}
    void display() const{
        cout<<hour<<":"<<minutes<<":"<<seconds<<endl;
    }

    time add(time x){


        time t;
        t.seconds=seconds+x.seconds;
        if(t.seconds>59){
            t.seconds-=60;
            minutes++;
        }
       
        t.minutes=minutes+x.minutes;
        if(t.minutes>59){
            t.minutes-=60;
            hour++;
        }
        t.hour=hour+x.hour;

        return t;}
};
int main()
{
    time t0;
    time t1(5,30,10);
    time t2(5,30,40);
    t0=t1.add(t2);
    cout<<"total time is ";
    t0.display();
    cout<<endl;
 return 0;}

Output:

You might also like