#include
using namespace std;
int main()
{
char ch;
while((ch = cin.get()) != '@') //首先声明一个char类型的ch,在输入之后进行判断
{
if(ch >= 'A' && ch <= 'Z')
cout << (char)(ch + ('a' - 'A'));
else
cout << (char)(ch - ('a' - 'A'));
}
cout << endl;
return 0;
}
#include
using namespace std;
int main()
{
double donation[10];
double sum;
int count = 0;
cout<<"请输入10个值:";
for(int i=0;i<10;i++)
{
if(cin>>donation[i])
sum +=donation[i];
else
break;
}
cout<<"平均值为:"<(sum/10))
count++;
}
cout<<"一共有"<
#include
using namespace std;
int main()
{
cout << "Please enter one of the following choices:" << endl << "c) carnivore p) pianist" << endl << "t) tree g) game" << endl;
cout << "Please enter a c , p , t , or g: ";
char ch;
while(cin.get(ch).get() && (ch != 'c' && ch != 'p' && ch != 't' && ch != 'g')) //注意cin.get(ch).get()
{
cout << "Please enter a c , p , t , or g: ";
}
switch(ch){
case 'c' : cout << "A maple is a carnivore." << endl; break;
case 'p' : cout << "A maple is a pianist." << endl; break;
case 't' : cout << "A maple is a tree." << endl; break;
case 'g' : cout << "A maple is a game." << endl; break;
}
return 0;
}
#include
using namespace std;
struct bop
{
char fullname[50];
char title[50];
char bopname[50];
int preference;
};
void display_by_name();
void display_by_title();
void display_by_bopname();
void diaplay_by_preference();
char ch;
bop people[5] = {
{
"Wimp Macho",
"BOSS",
"WM",
0
},
{
"Raki Rhodes",
"Manager",
"Junior Programmer",
2
},
{
"Celia Laiter",
"MIPS",
"CL",
1
},
{
"Hoppy Hipman",
"Analyst Trainee",
"AT",
1
},
{
"Pat Hand",
"Student",
"LOOPY",
2
}
};
int main()
{
cout<<"a. display by name b. display by title" << endl << "c. display by bopname d. display by preference" << endl << "q. quit" << endl << "Enter your choice: ";
while(cin>>ch&&ch!='q')
{
switch(ch){
case'a':display_by_name();break;
case'b':display_by_title();break;
case'c':display_by_bopname();break;
case'd':diaplay_by_preference();break;
}
cout<<"Enter your choice:"<
#include
using namespace std;
double money;
int main()
{
for(int i=0;i<10;i++)
{
while(cin>>money&&(money>0)){
if(money<=5000)
cout<5000&&money<=15000)
cout<<(money-5000) * 0.1 + 5000 * 0<15000&&money<=35000)
cout<<(money-15000) * 0.15 + 10000 * 0.1 + 5000*0<
#include
#include
using namespace std;
struct people
{
string name;
double money;
int flag;
};
int main()
{
cout << "请输入捐献者数目: ";
int num , GP = 0;
cin >> num; //以这种方式输入完了数字之后后面要加上cin.get()
cin.get();
people *team = new people[num];
for(int i = 0 ; i < num ; ++ i)
{
getline(cin , team[i].name);
cin >> team[i].money;
cin.get();
if(team[i].money > 10000){
team[i].flag = 1; //使用另一个变量标记捐款超过10000的人
++ GP;
}
else
team[i].flag = 0;
}
cout << "Patrons: ";
for(int i = 0 ; i < num ; ++ i){
if(team[i].flag)
cout << team[i].name << " ";
}
cout << endl;
cout << "Others: ";
if(GP == num)
cout << "none" << endl;
else{
for(int i = 0 ; i < num ; ++ i){
if(!(team[i].flag))
cout << team[i].name << " ";
}
}
cout << endl;
return 0;
}
#include
#include
using namespace std;
int main()
{
cout << "Enter words (q to quit) :" << endl;
string ch;
int num1 = 0 , num2 = 0 , num3 = 0;
while(cin >> ch) //确保每次可以读取一个单词,string可以自动读取每一个单词,可以使用ch[i]的方式来选择一个单词中的第几个词
{
if(ch[0] == 'q' && ch[1] == 0) //确保不是以q为开头的单词而只是一个q
break;
if(ch[0] == 'a' || ch[0] == 'A' || ch[0] == 'e' || ch[0] == 'E' || ch[0] == 'i' || ch[0] =='I' || ch[0] == 'o' || ch[0] == 'O' || ch[0] == 'u' || ch[0] == 'U')
++ num1;
else if(ch[0] >= 'a' && ch[0] <='z' || ch[0] >= 'A' && ch[0] <='Z')
++ num2;
else ++ num3;
}
cout << num1 <<" words beginning with vowels" << endl << num2 <<" words beginning with consonants" << endl << num3 <<" others" << endl;
return 0;
}
#include
#include
using namespace std;
int main()
{
ifstream infile;
infile.open("in.txt");
char ch;
int num = 0;
while(infile >> ch) //用于读取对应文件中的字符
{
if(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')
++ num;
}
cout << num << endl;
return 0;
}
#include
#include
#include
using namespace std;
struct people{
string name;
double money;
int flag;
};
int main()
{
fstream infile;
infile.open("in.txt");
int num , GP = 0;
infile >> num;
infile.get();
people *p = new people[num];
for(int i = 0 ; i < num ; ++ i){
getline(infile , (p + i) -> name);
infile >> (p + i) -> money;
infile.get();
if((p + i) -> money > 10000){
(p + i) -> flag = 1;
++ GP;
}
else
(p + i) -> flag = 0;
}
cout << "Patrons: ";
for(int i = 0 ; i < num ; ++ i){
if((p + i) -> flag)
cout << (p + i) -> name << " ";
}
cout << endl;
cout << "Others: ";
if(GP == num)
cout << "none" << endl;
else{
for(int i = 0 ; i < num ; ++ i){
if(!((p + i) -> flag))
cout << (p + i) -> name << " ";
}
}
cout << endl;
return 0;
}
有一部分需要在熟悉一下