-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.cpp
More file actions
135 lines (115 loc) · 3.73 KB
/
Copy pathCar.cpp
File metadata and controls
135 lines (115 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "Car.h"
#include <iostream>
#include <cstring>
#include <iomanip>
//Konstruktor Domyślny
Car::Car() = default;
//Destruktor Domyślny
Car::~Car()= default;
//Konstruktor Kopiujący
Car::Car(const Car& src)
: Vehicle(src._manufacturer, src._name, src._year, src._power), _seats(src._seats), _motors(src._motors) {
strcpy(_body, src._body);
strcpy(_color, src._color);
}
//Konstruktor
Car::Car(const char manufacturer[25], const char name[25],
unsigned year, float power,const char body[25],
const char color[25], unsigned seats, unsigned motors)
: Vehicle(manufacturer, name, year, power), _seats(seats), _motors(motors) {
strcpy(_body, body);
strcpy(_color, color);
}
//Przeładowanie operatora "="
Car& Car::operator=(const Car & src) {
strcpy(this->_body, src._body);
strcpy(this->_color, src._color);
strcpy(this->_name, src._name);
strcpy(this->_manufacturer, src._manufacturer);
this->_power = src._power;
this->_seats = src._seats;
this->_motors = src._motors;
this->_year = src._year;
return *this;
}
//Wyświetlania dancyh obiektów
void Car::describe() {
std::cout << std::setw(10) << this->_manufacturer << " | " << std::setw(20) << this->_name << " | "
<< std::setw(4) << this->_year << " | " << std::setw(6) << this->_power << " HP | Nadwozie:"
<< std::setw(10) <<this->_body << " | Kolor:" << std::setw(15) << this->_color << " | Miejsca:"
<< std::setw(3)<< this->_seats << " | Silniki: " << std::setw(1) << this->_motors << "\n";
}
//Metoda zwracająca rozmiar obiektu
int Car::size() {
return sizeof(*this);
}
//Metoda Pozwalająca ręcznie wpisać danie do obiektu
int Car::setData(){
const char *manu[25];
const char *name[25];
unsigned year;
float power;
const char *body[25];
const char *color[25];
unsigned seats;
unsigned motors;
std::cout << "\nPodaj nazwę producenta samochodu: ";
std::cin.ignore();
std::cin.getline((char *) manu, 25);
if(std::cin.fail()){
std::cout << "\nBłąd! Błędne dane!\n";
return 1;
}
std::cout << "\nPodaj nazwę samochodu: ";
std::cin.getline((char *) name, 25);
if(std::cin.fail()){
std::cout << "\nBłąd! Błędne dane!\n";
return 1;
}
std::cout << "\nPodaj rok produkcji samochodu: ";
std::cin >> year;
if(std::cin.fail()){
std::cout << "\nBłąd! Błędne dane!\n";
return 1;
}
std::cout << "\nPodaj moc samochodu: ";
std::cin >> power;
if(std::cin.fail()){
std::cout << "\nBłąd! Błędne dane!\n";
return 1;
}
std::cout << "\nPodaj rodzaj nadowzia samochodu: ";
std::cin.ignore(1000,'\n');
std::cin.getline((char *) body, 25);
if(std::cin.fail()){
std::cout << "\nBłąd! Błędne dane!\n";
return 1;
}
std::cout << "\nPodaj kolor karoseri samochodu: ";
std::cin.getline((char *) color, 25);
if(std::cin.fail()){
std::cout << "\nBłąd! Błędne dane!\n";
return 1;
}
std::cout << "\nPodaj ilość miejsc w samochodzie: ";
std::cin >> seats;
if(std::cin.fail()){
std::cout << "\nBłąd! Błędne dane!\n";
return 1;
}
std::cout << "\nPodaj ilość silników w samochodzie: ";
std::cin >> motors;
if(std::cin.fail()){
std::cout << "\nBłąd! Błędne dane!\n";
return 1;
}
strcpy(this->_manufacturer, reinterpret_cast<const char *>(manu));
strcpy(this->_name, reinterpret_cast<const char *>(name));
_year = year;
_power = power;
strcpy(this->_body, reinterpret_cast<const char *>(body));
strcpy(this->_color, reinterpret_cast<const char *>(color));
_seats = seats;
_motors = motors;
return 0;
}