我重新学习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
154
155
156
157
158
#include<iostream>
using namespace std;

struct man
{
char first_name[10];
char last_name[10];
char grade;
int age;
};
int main()
{
man yew;
cout << "What...? ";
cin.getline(yew.first_name,10);
cout << endl << "What...? ";
cin.getline(yew.last_name, 10);
cout << endl << "what...? ";
cin >> yew.grade;
cout << endl << "what...? ";
cin >> yew.age;
cout << 'n' << "Name: " << yew.last_name << " , " << yew.first_name;
yew.grade = yew.grade + 1;
cout << 'n' << "Grade: " << yew.grade << 'n' << "Age: " << yew.age << 'n';
return 0;
}
4.11.2
#include<iostream>
#include <string>
using namespace std;

int main()
{
//const int ArSize = 20;
string name;
string dessert;
cout << "E...: n";
getline(cin, name);
cout << "E...dessert: n";
getline(cin, dessert);
cout << "I..." << dessert;
cout << " for..." << name << ".n";
return 0;
}
4.11.3
#include <iostream>
#include<cstring>

using namespace std;

int main()
{
char name[20];
char xing[20];
char fullname[41];
cout << "E...: ";
cin.getline(name, 20);
cout << 'n' << "E...: ";
cin.getline(xing, 20);
strcpy(fullname, name);
strcat(fullname, ", ");
strcat(fullname, xing);
cout << 'n' << "H...: " << fullname;
return 0;
}
4.11.4
#include <iostream>
#include<string>

using namespace std;

int main()
{
string name;
string xing;
string fullname;
cout << "E...: ";
getline(cin, name);
cout << 'n' << "E...: ";
getline(cin, xing);
fullname = xing + ", " + name;
cout << 'n' << "H...: " << fullname;
return 0;
}
4.11.5
#include <iostream>

using namespace std;

const int Size = 20;

struct CandyBar
{
char name[Size];
double weight;
int kaluli;
}snack=
{
"Mocha Munch",
2.3,
350
};

int main()
{
cout << snack.name << 'n' << snack.weight << 'n' << snack.kaluli;
return 0;
}
4.11.6
#include <iostream>

using namespace std;

const int Size = 30;

struct pisa
{
char name[Size];
double dia;
double weight;
}William;
int main()
{
cin.getline(William.name, Size);
cin >> William.dia;
cin >> William.weight;
cout << William.name << William.dia << William.weight;
return 0;
}
4.11.7
#include <iostream>
#include <string>
using namespace std;

const int Size = 30;

struct pisa
{
char name[Size];
double dia;
double weight;
};
int main()
{
pisa *pa = new pisa;
cin >> pa->dia;
string str;
str = "n";
getline(cin, str);
cin.getline(pa->name,Size);
cin >> pa->weight;
cout << "公司名称: ";
cout << pa->name;
cout << endl <<"披萨饼直径:"<< pa->dia;
cout << endl <<"披萨饼重量:"<< pa->weight;
delete pa;
return 0;
}

—写于2017.5.15