Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Car
- {
- private:
- string licensePlate_;
- int horsePower_;
- double weight_;
- char engine_;
- friend class CarCatalog;
- public:
- Car(string, int, double, char);
- Car();
- };
- Car::Car(string licensePlate, int horsePower, double weight, char engine):
- licensePlate_(licensePlate), horsePower_(horsePower), weight_(weight), engine_(engine)
- {
- }
- Car::Car()
- {
- }
- class CarCatalog
- {
- private:
- friend class Car;
- Car catalogArray_[6];
- int counter_ = 0;
- public:
- CarCatalog();
- void clearArray()
- {
- for(int i = 0; i < 7; i++)
- {
- catalogArray_[i].horsePower_ = 0;
- }
- }
- void showCatalog()
- {
- for(int i = 0; i < 7; i++)
- {
- cout << catalogArray_[i].licensePlate_ << " " << catalogArray_[i].horsePower_ << " ";
- }
- }
- void addCar(Car toAdd)
- {
- catalogArray_[counter_] = toAdd;
- counter_++;
- /*if(counter_ != 0)
- {
- if(toAdd.horsePower_ < catalogArray_[counter_ - 1].horsePower_)
- {
- do
- {
- catalogArray_[counter_] = catalogArray_[counter_ - 1];
- catalogArray_[counter_ - 1] = toAdd;
- counterWhile++;
- }
- while(toAdd.horsePower_ < catalogArray_[counter_ - 1].horsePower_ && counter_ < 0);
- counter_ = counter_ + counterWhile;
- }
- else
- {
- catalogArray_[counter_] = toAdd;
- counter_++;
- cout << "B" << endl;
- showCatalog();
- cout << endl;
- }
- }
- else
- {
- catalogArray_[counter_] = toAdd;
- counter_++;
- cout << "C" << endl;
- showCatalog();
- cout << endl;
- }*/
- }
- };
- CarCatalog::CarCatalog()
- {
- }
- int main()
- {
- CarCatalog catalog;
- catalog.clearArray();
- string plate;
- int power;
- double tons;
- char eng;
- do
- {
- cin >> plate;
- }
- while(plate.size() != 4);
- while(!(cin >> power))
- {
- cin.clear();
- cin.sync();
- }
- while(!(cin >> tons))
- {
- cin.clear();
- cin.sync();
- }
- do
- {
- cin >> eng;
- }
- while(eng != 'B' && eng != 'D' && eng != 'H' && eng != 'E');
- Car car1(plate, power, tons, eng);
- do
- {
- cin >> plate;
- }
- while(plate.size() != 4);
- while(!(cin >> power))
- {
- cin.clear();
- cin.sync();
- }
- while(!(cin >> tons))
- {
- cin.clear();
- cin.sync();
- }
- do
- {
- cin >> eng;
- }
- while(eng != 'B' && eng != 'D' && eng != 'H' && eng != 'E');
- Car car2(plate, power, tons, eng);
- do
- {
- cin >> plate;
- }
- while(plate.size() != 4);
- while(!(cin >> power))
- {
- cin.clear();
- cin.sync();
- }
- while(!(cin >> tons))
- {
- cin.clear();
- cin.sync();
- }
- do
- {
- cin >> eng;
- }
- while(eng != 'B' && eng != 'D' && eng != 'H' && eng != 'E');
- Car car3(plate, power, tons, eng);
- do
- {
- cin >> plate;
- }
- while(plate.size() != 4);
- while(!(cin >> power))
- {
- cin.clear();
- cin.sync();
- }
- while(!(cin >> tons))
- {
- cin.clear();
- cin.sync();
- }
- do
- {
- cin >> eng;
- }
- while(eng != 'B' && eng != 'D' && eng != 'H' && eng != 'E');
- Car car4(plate, power, tons, eng);
- do
- {
- cin >> plate;
- }
- while(plate.size() != 4);
- while(!(cin >> power))
- {
- cin.clear();
- cin.sync();
- }
- while(!(cin >> tons))
- {
- cin.clear();
- cin.sync();
- }
- do
- {
- cin >> eng;
- }
- while(eng != 'B' && eng != 'D' && eng != 'H' && eng != 'E');
- Car car5(plate, power, tons, eng);
- do
- {
- cin >> plate;
- }
- while(plate.size() != 4);
- while(!(cin >> power))
- {
- cin.clear();
- cin.sync();
- }
- while(!(cin >> tons))
- {
- cin.clear();
- cin.sync();
- }
- do
- {
- cin >> eng;
- }
- while(eng != 'B' && eng != 'D' && eng != 'H' && eng != 'E');
- Car car6(plate, power, tons, eng);
- catalog.addCar(car1);
- catalog.addCar(car2);
- catalog.addCar(car3);
- catalog.addCar(car4);
- catalog.addCar(car5);
- catalog.addCar(car6);
- catalog.showCatalog();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement