@GuGo1991
268 / 262 / 93
Регистрация: 02.08.2012
Сообщений: 609
|
13.02.2014, 02:45
|
#2
|
Сообщение было отмечено автором темы, экспертом или модератором как ответ
Bubbles, сначала заполняете, потом выполняется поиск.
Вводите количество автомагазинов. В каждом указываете количество моделей.
Потом модель, цвет, цена и т. д.
C++ | 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
136
137
138
139
140
141
142
143
144
145
| #include <iostream>
class aShop
{
private:
std::string shopName;
std::string shopAddress;
std::string shopTelNumber;
int shQuant, index;
public:
class aModel
{
private:
std::string model;
std::string color;
int price, index;
public:
std::string* mData;
int* aPrice;
aModel()
{
create_aPrice();
create_mData();
}
void saveData(int n)
{
index = n;
mData[index] = model + " " + color;
aPrice[index] = price;
}
void removeData()
{
delete [] mData, aPrice;
}
void create_mData()
{
mData = new std::string[100];
}
void create_aPrice()
{
aPrice = new int[100];
}
void setData(std::string m, std::string c, int p)
{
model = m;
color = c;
price = p;
}
};
std::string* shData;
aShop() {}
void saveData(int n)
{
index = n;
shData[index] = shopName + " " +
shopAddress + " " +
shopTelNumber;
}
void removeData()
{
delete [] shData;
}
void setQuant(int q)
{
shQuant = q;
shData = new std::string[shQuant];
}
void setData(std::string name,
std::string address,
std::string number)
{
shopName = name;
shopAddress = address;
shopTelNumber = number;
}
};
int main()
{
std::cout << "Let's fill some data.\n";
int shQ, mQ, price, index = 0, end = 0;
bool result = false;
int* count;
std::string name, address, number, model, color;
aShop shObject;
aShop::aModel aObject;
std::cout << "Enter shop quantity: "; std::cin >> shQ;
std::cout << "\n-----------------------------\n";
shObject.setQuant(shQ);
count = new int[shQ];
for(int i = 0; i < shQ; i++)
{
std::cout << "\nEnter shop name, address and phone number.\n";
std::cout << "Shop name: "; std::cin >> name;
std::cout << "Address: "; std::cin >> address;
std::cout << "Pnone number: "; std::cin >> number;
shObject.setData(name, address, number);
shObject.saveData(i);
std::cout << "\nEnter car model quantity: "; std::cin >> mQ;
count[i] = mQ;
for(int j = 0; j < mQ; j++)
{
std::cout << "Enter model name, color and price.\n" <<
"#" << j + 1 << "\n";
std::cout << "Model: "; std::cin >> model;
std::cout << "Color: "; std::cin >> color;
std::cout << "Price: "; std::cin >> price;
aObject.setData(model, color, price);
aObject.saveData(index);
index++;
}
std::cout << "\n-----------------------------\n";
}
std::cout << "\nData is filled.\n\n";
std::cout << "Enter model and color to find shop.\n";
std::cout << "Model: "; std::cin >> model;
std::cout << "Color: "; std::cin >> color;
index = 0;
for(int i = 0; i < shQ; i++)
{
end += count[i];
for(int j = index; j < end; j++)
{
if(model + " " + color == aObject.mData[j])
{
std::cout << "\nThere is a match.\n";
std::cout << shObject.shData[i] << "\n\n";
result = true;
}
}
index += count[i];
}
if(result == false)
std::cout << "\nThere is no match.\n\n";
shObject.removeData();
aObject.removeData();
system("pause");
return 0;
} |
|
Добавлено через 47 минут
Забыл в предидущем варианте занести массивы в private.
C++ | 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
| #include <iostream>
class aShop
{
private:
std::string shopName;
std::string shopAddress;
std::string shopTelNumber;
std::string* shData;
int shQuant, index;
public:
class aModel
{
private:
std::string model;
std::string color;
int price, index;
std::string* mData;
int* aPrice;
public:
aModel()
{
create_aPrice();
create_mData();
}
void saveData(int n)
{
index = n;
mData[index] = model + " " + color;
aPrice[index] = price;
}
void removeData()
{
delete [] mData, aPrice;
}
void create_mData()
{
mData = new std::string[100];
}
void create_aPrice()
{
aPrice = new int[100];
}
std::string callMData(int n)
{
return mData[n];
}
void setData(std::string m, std::string c, int p)
{
model = m;
color = c;
price = p;
}
};
aShop() {}
void saveData(int n)
{
index = n;
shData[index] = shopName + " " +
shopAddress + " " +
shopTelNumber;
}
void removeData()
{
delete [] shData;
}
void setQuant(int q)
{
shQuant = q;
shData = new std::string[shQuant];
}
std::string callShData(int n)
{
return shData[n];
}
void setData(std::string name,
std::string address,
std::string number)
{
shopName = name;
shopAddress = address;
shopTelNumber = number;
}
};
int main()
{
std::cout << "Let's fill some data.\n";
int shQ, mQ, price, index = 0, end = 0;
bool result = false;
int* count;
std::string name, address, number, model, color;
aShop shObject;
aShop::aModel aObject;
std::cout << "Enter shop quantity: "; std::cin >> shQ;
std::cout << "\n-----------------------------\n";
shObject.setQuant(shQ);
count = new int[shQ];
for(int i = 0; i < shQ; i++)
{
std::cout << "\nEnter shop name, address and phone number.\n";
std::cout << "Shop name: "; std::cin >> name;
std::cout << "Address: "; std::cin >> address;
std::cout << "Pnone number: "; std::cin >> number;
shObject.setData(name, address, number);
shObject.saveData(i);
std::cout << "\nEnter car model quantity: "; std::cin >> mQ;
count[i] = mQ;
for(int j = 0; j < mQ; j++)
{
std::cout << "Enter model name, color and price.\n" <<
"#" << j + 1 << "\n";
std::cout << "Model: "; std::cin >> model;
std::cout << "Color: "; std::cin >> color;
std::cout << "Price: "; std::cin >> price;
aObject.setData(model, color, price);
aObject.saveData(index);
index++;
}
std::cout << "\n-----------------------------\n";
}
std::cout << "\nData is filled.\n\n";
std::cout << "Enter model and color to find shop.\n";
std::cout << "Model: "; std::cin >> model;
std::cout << "Color: "; std::cin >> color;
index = 0;
for(int i = 0; i < shQ; i++)
{
end += count[i];
for(int j = index; j < end; j++)
{
if(model + " " + color == aObject.callMData(j))
{
std::cout << "\nThere is a match.\n";
std::cout << shObject.callShData(i) << "\n\n";
result = true;
}
}
index += count[i];
}
if(result == false)
std::cout << "\nThere is no match.\n\n";
shObject.removeData();
aObject.removeData();
system("pause");
return 0;
} |
|
1
|