Tips:
1.cin >> str //用于接收一个字符串时,遇到空格则停止
2.getling(cin,string) //用于接收一行字符串,可以接收空格,但是同样不会丢弃换行符
3.cin >> int/*在输入并读取之后,换行符依旧在队列中,此时若是继续用cin>>输入则会因为 >> 操作符的原因,自动跳过队列前空白。而如果使用getline()的系列方法来读取字符串,则会因为第一个字符是换行符而直接停止读取。*/
1——10题综合如下
#include<iostream>
#include<array>
#include<cstring>
using namespace std;
/*struct car
{
string Productor;
int Year_Of_Pro;
};*/
int main()
{
// No.1
/*int i,j,step = 0;
cout << "input two numbers: ";
cin >> i >> j;
if(i<j)
{
for(i ; i <= j ; i++)
step+=i;
}
else
{
for(j ; j <= i ; j++)
step+=j;
}
cout<< "The amount of between num:"<<step<<endl;
// N0.2
array <long double,101>factorials;
factorials[0] = factorials[1] = 1.0;
for(int i = 2; i<101 ; i++)
factorials[i] = factorials[i-1] * i;
for(int i = 0; i<101 ; i++)
cout<< i <<"! = "<<factorials[i]<<endl;
cout<<"No.3"<<endl;
int i,step = 0;
cout << "input the number:";
cin >> i;
while(i!=0)
{
step += i;
cout<<"multi plus:"<< step <<endl;
cout<<"input the number:";
cin>> i ;
}
cout << "the program is over"<<endl;
cout << "No.4" <<endl;
double D_Daphne = 100;
double D_Cleo = 100;
int year = 0;
while(D_Cleo <= D_Daphne)
{
D_Daphne = 0.1 * 100 + D_Daphne;
D_Cleo = 0.05 * D_Cleo + D_Cleo;
year ++;
}
cout << "this is the "<<year<<" year."<<endl;
cout << "Daphne's Deposit is:"<<D_Daphne<<endl;
cout << "Cleo's Deposit is:"<<D_Cleo<<endl;
cout << "No.5"<<endl;
string Month[12] =
{
"January","February","March","April",
"May", "June" ,"July","August","September",
"October","November","December"
};
int Amount[12];
int temp = 0;
for(int i = 0; i < 12 ; i++)
{
cout <<"Selling Amount of "<<Month[i]<<" :";
cin >> Amount[i];
temp += Amount[i];
}
cout << "The Year Selling Amount is:"<<temp<<endl;
cout<< "No.6"<<endl;
string Month[12] =
{
"January","February","March","April",
"May", "June" ,"July","August","September",
"October","November","December"
};
int Amount[3][12];
int i,j,temp1=0;
int temp2 = 0;
cout<<"initializing data:";
for(i=0 ; i<12 ; i++)
{
for(j=0 ; j<3 ; j++)
{
cin>> Amount[j][i];
}
}
cout<<"print detail of selling:"<<endl;
for(i=0 ; i<12 ; i++)
{
cout << Month[i]<<":\t";
for(j=0 ; j<3 ; j++)
{
cout << Amount[j][i]<<"\t";
temp1 += Amount[j][i];
}
cout<<endl;
}
cout << "the full selling amount is:"<< temp1<<endl;
for(i = 0; i<3 ;i++)
{
for(j = 0; j<12; j++)
{
temp2 += Amount[i][j];
}
cout <<"the Amount of "<<i+1<<" year:"<<temp2<<endl;
temp2 = 0;
}
cout << "No.7"<<endl;
cout<<"how many cars do you wish to catalog?"<<endl;
int i;
cin >> i;
cin.get();
car *C_num = new car[i];
for(int j = 0 ; j<i ; j++)
{
cout << "car #"<<j+1<<endl;
cout << "Please inter the make:";
getline(cin,C_num[j].Productor);
cout << "Please inter the made:";
cin >> C_num[j].Year_Of_Pro;
cin.get();
}
cout << "Here is your collection:"<<endl;
for (int j = 0 ; j<i ; j++)
{
cout << C_num[j].Year_Of_Pro << " " << C_num[j].Productor <<endl;
}
cout << "No.8:"<<endl;
char Word[20] = "none";
int counting = 0;
while(1)
{
cin >> Word;
if(strcmp(Word,"done") != 0)
counting++;
else
break;
}
cout << "entered a total of "<<counting << " words." << endl;
cout << "No.9:" << endl;
string Word = "none";
int counting = 0;
while(1)
{
cin >> Word;
if(Word != "done")
counting++;
else
break;
}
cout << "entered a total of "<<counting << " words." << endl;
cout << "No.10" << endl;
cout << "input how many stars do you need:";
int Num;
cin >> Num;
char star[Num][Num];
for(int i = 0 ; i < Num ; i++)
{
for(int j = 0 ; j<Num ; j++)
{
if( j < (Num -1 - i))
star[i][j] = '.';
else
star[i][j] = '*';
}
}
for(int i = 0 ; i < Num ; i++)
{
for(int j = 0 ; j < Num ; j++)
{
cout << star[i][j]<< "\t";
}
cout<<endl;
}
return 0;
*/
}