0% found this document useful (0 votes)
109 views1 page

Object Oriented Programming Using C++ (0957-0957)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views1 page

Object Oriented Programming Using C++ (0957-0957)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Appendix G

930

Int(int ii) //create and initialize an Int


{ i = ii; }
void add(Int i2, Int i3) //add two Ints
{ i = i2.i + i3.i; }
void display() //display an Int
{ cout << i; }
};
////////////////////////////////////////////////////////////////
int main()
{
Int Int1(7); //create and initialize an Int
Int Int2(11); //create and initialize an Int
Int Int3; //create an Int

Int3.add(Int1, Int2); //add two Ints


cout << “\nInt3 = “; Int3.display(); //display result
cout << endl;
return 0;
}

2.
// ex6_2.cpp
// uses class to model toll booth
#include <iostream>
using namespace std;
#include <conio.h>

const char ESC = 27; //escape key ASCII code


const double TOLL = 0.5; //toll is 50 cents
////////////////////////////////////////////////////////////////
class tollBooth
{
private:
unsigned int totalCars; //total cars passed today
double totalCash; //total money collected today
public: //constructor
tollBooth() : totalCars(0), totalCash(0.0)
{ }
void payingCar() //a car paid
{ totalCars++; totalCash += TOLL; }
void nopayCar() //a car didn’t pay
{ totalCars++; }
void display() const //display totals
{ cout << “\nCars=” << totalCars
<< “, cash=” << totalCash
<< endl; }
};

You might also like