-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.cpp
More file actions
102 lines (74 loc) · 2.75 KB
/
2.cpp
File metadata and controls
102 lines (74 loc) · 2.75 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
#include <iostream>
#include <string>
using namespace std;
struct WashingMachine {
string brand;
string color;
double width;
double depth;
double height;
int power;
int spinSpeed;
int heatingTemperature;
};
void inputWashingMachineInfo(WashingMachine& machine);
void printWashingMachineTable(const WashingMachine* machines, int size);
int main() {
int machineCount = 0;
int maxMachines = 2;
WashingMachine* machines = new WashingMachine[maxMachines];
char addMore = 'y';
while (addMore == 'y' || addMore == 'Y') {
if (machineCount == maxMachines) {
maxMachines *= 2;
WashingMachine* temp = new WashingMachine[maxMachines];
for (int i = 0; i < machineCount; ++i) {
temp[i] = machines[i];
}
delete[] machines;
machines = temp;
}
cout << "\nEnter details for washing machine " << (machineCount + 1) << ":\n";
inputWashingMachineInfo(machines[machineCount]);
machineCount++;
cout << "Do you want to add another washing machine? (y/n): ";
cin >> addMore;
cin.ignore();
}
printWashingMachineTable(machines, machineCount);
delete[] machines;
return 0;
}
void inputWashingMachineInfo(WashingMachine& machine) {
cout << "Enter brand: ";
getline(cin, machine.brand);
cout << "Enter color: ";
getline(cin, machine.color);
cout << "Enter width (cm): ";
cin >> machine.width;
cout << "Enter depth (cm): ";
cin >> machine.depth;
cout << "Enter height (cm): ";
cin >> machine.height;
cout << "Enter power (W): ";
cin >> machine.power;
cout << "Enter spin speed (rpm): ";
cin >> machine.spinSpeed;
cout << "Enter heating temperature (°C): ";
cin >> machine.heatingTemperature;
cin.ignore();
}
void printWashingMachineTable(const WashingMachine* machines, int size) {
cout << "Brand Color Width (cm) Depth (cm) Height (cm) Power (W) Spin Speed (rpm) Heating Temperature (°C)\n";
cout << "-------------------------------------------------------------------------------------------------------------------\n";
for (int i = 0; i < size; ++i) {
cout << machines[i].brand << " "
<< machines[i].color << " "
<< machines[i].width << " "
<< machines[i].depth << " "
<< machines[i].height << " "
<< machines[i].power << " "
<< machines[i].spinSpeed << " "
<< machines[i].heatingTemperature << endl;
}
}