0% found this document useful (0 votes)
6 views4 pages

OOP Lab Assignment 03 Solutions

The document contains code for two C++ programs: 1. A tollbooth class that tracks the number of cars that pass through and the money collected. It has methods to increment counts for paying and non-paying cars and displays the totals. 2. A time class that represents a time as hours, minutes, seconds. It overloads operators to add two time objects and returns the sum. The main function demonstrates adding two time objects and displaying the result.

Uploaded by

Mr Mudassir
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)
6 views4 pages

OOP Lab Assignment 03 Solutions

The document contains code for two C++ programs: 1. A tollbooth class that tracks the number of cars that pass through and the money collected. It has methods to increment counts for paying and non-paying cars and displays the totals. 2. A time class that represents a time as hours, minutes, seconds. It overloads operators to add two time objects and returns the sum. The main function demonstrates adding two time objects and displaying the result.

Uploaded by

Mr Mudassir
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

(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'){
        [Link]();
        cout<<" **..paying car..**"<<endl; }
       else if(key=='N'|| key=='n'){
        [Link]();
        cout<<" **..Non-paying car..**"<<endl;}
       else if(key==27){
        [Link]();
        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;
        [Link]=seconds+[Link];
        if([Link]>59){
            [Link]-=60;
            minutes++;
        }
       
        [Link]=minutes+[Link];
        if([Link]>59){
            [Link]-=60;
            hour++;
        }
        [Link]=hour+[Link];

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

Output:

You might also like