c++primerplus第六版第五章习题答案
- 格式:docx
- 大小:12.93 KB
- 文档页数:6
//1
/*
#include
using namespace std;
int main()
{
cout <<"请输入一个较小的整数:";
int min;
cin >> min;
cout <<"请输入一个较大的整数:";
int max;
cin >> max;
int he=0;
for (int i = min; i <= max; i++)
he = i + he;
cout <<"这两个数之间所有数相加后的和为:"<< he<
system("pause");
return 0;
}*/
//2
/*
#include
#include
using namespace std;
const int Arsize = 101;
int main()
{
array aa ;
aa[1] = aa[0] = 1;
for (int i = 2; i < Arsize; i++)
aa[i] = i*aa[i - 1];
for (int i = 0; i < Arsize; i++)
cout << i <<"!="<< aa[i] << endl;
system("pause");
return 0;
}*/
//3
/*
#include
using namespace std;
int main()
{ cout <<"请输入一个数字"<< endl;
int m=0, n;
do
{
cin >> n;
m = m + n;
cout <<"累计输入数字的和为:"<< m << endl;
}
while (n != 0);
system("pause");
return 0;
}*/
//4
/*
#include
using namespace std;
int main()
{
double daphne = 110, cleo = 105;
int i;
for (i = 1; daphne > cleo; i++)
{
daphne += 10;
cleo *= 1.05;
}
cout << i << endl << daphne << endl << cleo;
system("pause");
return 0;
}*/
//5
/*
#include
#include
using namespace std;
int main()
{
const int Month=12;
const int Number=12;
const string month[Month] =
{
"January" , "February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
};
int number[Number];
int he=0;
for (int i = 0; i < Month; i++)
{
cout << month[i];
cin >> number[i];
he += number[i];
}
for (int i = 0; i < Month; i++)
{
cout << month[i] <<"\t";
cout << number[i] <<"\t";
}
cout <<"和为:"<< he;
system("pause");
return 0;
}*/
//6
/*
#include
#include
using namespace std;
int main()
{
const int Month = 12;
const int Year = 3;
int number[Year][Month];
string y[Year] = { "first","second","third" };
int he[Year] = {0,0,0};
int h=0; cout <<"请输入每个月的销量"<< endl;
for (int year = 0; year < Year; year++)
{
cout << y[year] <<"\t";
for (int month = 0; month < Month; month++)
{
cin >> number[year][month];
he[year] += number[year][month];
cout <<"\t";
}
h =h+ he[year];
cout << he[year];
cout << endl;
}
cout << h;
system("pause");
return 0;
}*/
//7
/*
#include
#include
using namespace std;
struct car
{
string name;
int year;
};
int main()
{
int n;
cout <<"How many cars do you wish to catalog?";
cin >> n;
cin.get();
car *p = new car[n];
for (int i = 0; i < n; i++)
{
cout <<"Car #"<< i + 1 <<":"<< endl;
cout <<"Please enter the make:";
getline(cin,p[i].name);
cout <<"Please enter the your made:";
cin >> p[i].year; cin.get();
}
cout <<"Here is your collection:"<< endl;
for (int i = 0; i < n; i++)
cout << p[i].year << p[i].name << endl;
system("pause");
}*/
//8
/*
#include
#include
using namespace std;
int main()
{
char word[20];
int i=0;
cin >> word;
while (strcmp(word, "done") != 0)
{
i++;
cin >> word;
}
cout << i;
system("pause");
}*/
//9
/*
#include
#include
using namespace std;
int main()
{
string word;
int i = 0;
cin >> word;
while (word!="done")
{
i++;
cin >> word;
}
cout << i;
system("pause"); }*/
//10
#include
using namespace std;
int main()
{
int row;
char point = '.', star = '*';
cout <<"Enter number of rows: ";
cin >> row;
for (int m = 1; m <= row; m++)
{
int n;
for (n = 1; row - n >= m; n++)
{
cout << point;
}
for (n; n <=row; n++)
{
cout << star;
}
cout << endl;
}
system("pause");
}