Skip to content

Commit df3d319

Browse files
author
lulongfei
committed
update array and str
1 parent 6212216 commit df3d319

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

arrayone.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
3+
int main()
4+
{
5+
using namespace std;
6+
int yams[3];
7+
8+
yams[0] = 7;
9+
yams[1]= 8;
10+
yams[2] = 6;
11+
12+
int yamcosts[3] = {20, 30, 5};
13+
14+
cout << "Total yams = ";
15+
cout << yams[0] + yams[1] + yams[2] << " yams cost ";
16+
cout << "The package with " << yams[1] << " yams costs ";
17+
cout << yamcosts[1] << " cents per yam.\n";
18+
int total = yams[0] * yamcosts[0] + yams[1] * yamcosts[1];
19+
total = total + yams[2] * yamcosts[2];
20+
21+
cout << "The total yam expense is " << total << " cents.\n";
22+
cout << "\nSize of yams array = " << sizeof yams;
23+
cout << " bytes.\n";
24+
cout << "Size of one element = " << sizeof yams[0];
25+
cout << " bytes.\n";
26+
27+
return 0;
28+
}

instr1.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
3+
int main()
4+
{
5+
using namespace std;
6+
const int ArSize = 20;
7+
char name[ArSize];
8+
char dessert[ArSize];
9+
10+
cout << "Enter your name:\n";
11+
cin.getline(name, ArSize);
12+
cout << "Enter your favorite dessert: \n";
13+
cin.getline(dessert, ArSize);
14+
15+
cout << "I have some delicious " << dessert;
16+
cout << " for you, " << name << ".\n";
17+
18+
return 0;
19+
}

typecast.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
3+
int main()
4+
{
5+
using namespace std;
6+
int auks, bats, coots;
7+
auks = 19.99 + 11.99;
8+
9+
bats = (int) 19.99 + (int) 11.99;
10+
coots = int (19.99) + int (11.99);
11+
12+
cout << "auks = " << auks << ", bats = " << bats;
13+
cout << ", coots = " << coots << endl;
14+
15+
char ch = 'Z';
16+
cout << "The code for " << ch << " is ";
17+
cout << int(ch) << endl;
18+
cout << "Yes, the code is ";
19+
cout << static_cast<int>(ch) << endl;
20+
21+
return 0;
22+
23+
}

0 commit comments

Comments
 (0)