-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex03.cpp
42 lines (34 loc) · 909 Bytes
/
ex03.cpp
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
#include <iostream>
#include <cstring>
#include <new>
const int StructSize = 2;
struct chaff
{
char dross[20];
int slag;
};
chaff buffer[sizeof(chaff) * StructSize];
int main()
{
using std::cout;
using std::cin;
using std::endl;
chaff * input = new (buffer) chaff[StructSize];
char str[20] {'\0'};
for (int i = 0; i < StructSize; i++)
{
std::cout << "Enter name " << i + 1 << ": ";
cin.getline(str, 20);
strcpy(input[i].dross, str);
std::cout << "Enter the quantity " << i + 1 << ": ";
std::cin >> input[i].slag;
std::cin.get();
}
std::cout << std::endl;
for (int i = 0; i < StructSize; i++)
{
std::cout << "Dross for chaff " << i + 1 << " is: " << input[i].dross << std::endl;
std::cout << "Slag for chaff " << i + 1 << " is: " << input[i].slag << std::endl;
}
return 0;
}