Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TP_2.cpp: Określa punkt wejścia dla aplikacji konsoli.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <vector>
- #include <algorithm>
- #include <ctime>
- using namespace std;
- class CTrain
- {
- private:
- vector<char> train;
- public:
- CTrain(int length);
- int length() { return train.size(); }
- void addCar(char value) { train.push_back(value); }
- void addCar() { train.push_back( (rand() % 5) + 65 ); }
- void print();
- };
- CTrain::CTrain(int length)
- {
- srand(time(NULL));
- for (size_t i = 0; i < length; i++)
- {
- char car = (rand() % 5) + 65;
- train.push_back(car);
- }
- }
- void CTrain::print()
- {
- vector<char>::iterator it;
- for (it = train.begin(); it != train.end(); it++)
- {
- cout << *it;
- }
- cout << endl;
- }
- int main()
- {
- CTrain *train = new CTrain(10);
- cout << "train size:" << train->length() << endl;
- train->print();
- train->addCar('A');
- cout << "train size:" << train->length() << endl;
- train->print();
- train->addCar();
- train->print();
- if (_getch() == 27) cout << "50";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement