You are on page 1of 2

//CarPark.

h #ifndef CARPARK_H #define CARPARK_H #include <iostream> #include <string> using namespace std; class CarPark { private: double time; bool capacity; string model; int carNumber; public: CarPark(); CarPark(double, int); void setModle(string); void setCapacity(bool); string getModle(); void readCarNumber(); string toString(); }; #endif //CarPar.cpp #include "CarPark.h" #include <string> #include <sstream> CarPark::CarPark() { time = 0.0; carNumber = 0; model=""; capacity=false; } CarPark::CarPark(double t, int cN) { time=t; carNumber=cN; } void CarPark::setModle(string m) { model=m; } string CarPark::getModle() { return model; } void CarPark::setCapacity(bool c) {

capacity = c; } void CarPark::readCarNumber() { char c; stringstream ss; ss<<carNumber; while (ss.get(c)) cout<<c<<" "; } string CarPark::toString() { string s; stringstream ss1,ss2; ss2<<carNumber; s= "\nCar Plate Number = "+ss2.str(); s+= "\nCar Model = "+ model; ss1<< time; s+= "\nTime =:"+ss1.str(); if(capacity) s+="\nsorry there is no place!\n"; else s+="\nWelcome!\n"; return s; } #include "CarPark.h" #include <iostream> using namespace std; int main() { CarPark car1;//default constructor cout<<car1.toString(); cout<<endl; CarPark car2(12,5227);//parameter constructor car2.setModle("Myvi");//call set function car2.setCapacity(false); cout<<"The model of car is :"<<car2.getModle()<<endl;//call get function cout<<car2.toString(); //call fucntion to seprate digit car2.readCarNumber(); cout<<endl; system("pause"); return 0; }

You might also like