#include<iostream>#include<string>int main()
{
usingnamespacestd;
string month[12] =
{
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
int sale[12], sum = 0;
for (int i = 0; i < 12; i++)
{
cin >> sale[i];
sum += sale[i];
}
cout << "Sales in this year:\n\n";
for (int i = 0; i < 12; i++)
{
cout << month[i] << ": \t" << sale[i] << endl;
}
cout << "Sum of sales: " << sum;
cin.get();
cin.get();
}
5.6
#include<iostream>#include<string>int main()
{
usingnamespacestd;
string month[12] =
{
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
int sale[12][3], sum = 0;
for (int i = 0; i < 12; i++)
for (int j = 0; j < 3; j++)
{
cin >> sale[i][j];
sum += sale[i][j];
}
cout << "Sales in three years:\n\n";
for (int i = 0; i < 12; i++)
{
cout << month[i] << ": \t" ;
for (int j = 0; j < 3; j++)
{
cout << sale[i][j] << "\t";
}
cout << endl;
}
cout << "Sum of sales: " << sum;
cin.get();
cin.get();
}
5.7
#include<iostream>#include<string>usingnamespacestd;
struct car
{
string make;
int year;
};
int main()
{
int numOfCar;
cout << "How many cars do you wish to catalog? ";
cin >> numOfCar;
cin.get();
car * carInfo = new car[numOfCar];
for (int i = 0; i < numOfCar; i++)
{
cout << "Car #" << i+1 << ":\n"
<< "Please enter the make: ";
getline(cin, (carInfo + i)->make);
cout << "Please enter the year made: ";
(cin >> carInfo[i].year).get();
}
cout << "Here is your collection:\n";
for (int i = 0; i < numOfCar; i++)
{
cout << (carInfo + i)->year << " " << (carInfo + i)->make << endl;
}
delete [] carInfo;
cin.get();
cin.get();
return0;
}
5.8
#include<iostream>#include<cstring>usingnamespacestd;
int main()
{
cout << "Enter words (to stop, type the word done):\n";
char word[30];
int n = 0;
cin >> word;
while (strcmp(word, "done"))
{
cin >> word;
n++;
}
cout << "You entered a total of " << n << " words.";
cin.get();
cin.get();
}
5.9
#include<iostream>#include<cstring>#include<string>usingnamespacestd;
int main()
{
cout << "Enter words (to stop, type the word done):\n";
string word;
int n = 0;
cin >> word;
while (word != "done")
{
cin >> word;
n++;
}
cout << "You entered a total of " << n << " words.";
cin.get();
cin.get();
}
5.10
#include<iostream>usingnamespacestd;
int main()
{
cout << "Enter numbet of rows: ";
int row;
cin >> row;
for (int i = 1; i <= row; i++)
{
for (int j = 0; j < (row - i); j++)
cout << "."; //print"."for (int j = 0; j < i; j++)
cout << "*"; //print"*"cout << endl;
}
cin.get();
cin.get();
}