第六第七第九题没做,和其他练习大同小异
#include<iostream>
#include<fstream>
#include<cctype>
#define strsize 20
using namespace std;
struct bop
{
char fullname[strsize];
char title[strsize];
char bopname[strsize];
int preference;
};
int main()
{
/*cout << "No.1" <<endl;
char ch;
while((ch = cin.get())!= '@')
{
if(isalpha(ch) && islower(ch))
{ch = toupper(ch);
cout << ch;}
else if(isalpha(ch) && isupper(ch))
{ch = tolower(ch);
cout << ch;}
}
cout << "No.2" << endl;
double donation, average = 0;
double ar[10];
int i = 0;
int j = 0;
int n = 0;
cin >> donation;
while(cin.good())
{
ar[i] = donation;
i++;
if(i == 10)
break;
cin >> donation;
}
for (j = 0 ; j < i ; j++)
{
average += ar[j];
}
average = average / i;
for (j = 0 ; j < i ; j++)
{
if(ar[j] > average)
{
n++;
}
}
cout << "Average :"<< average <<endl;
cout << "Bigger than Ave:"<< n <<endl;
cout << "No.3"<< endl;
cout << "Please enter one of the following choices:"<<endl;
cout << "c) carnivore \t p) pianist \nt) tree \t g) game"<<endl;
cout << "Please enter a c, p, t, or g:";
char flag;
cin >> flag;
while(flag != 'c' && flag != 'p' && flag != 't' && flag != 'g')
{
cout << "Please enter a c, p, t, or g:";
cin >> flag;
}
switch (flag)
{
case 'c': cout << "Tiger is a carnivore"<<endl;
break;
case 'p': cout << "Chopin is an pianist"<<endl;
break;
case 't': cout << "Maple is a tree"<<endl;
break;
case 'g': cout << "No man sky is a game"<< endl;
break;
}
cout << "No.4"<<endl;
bop member[3] = {
{"Emma Watson", "Hige level" ,"Dora",0 },
{"Edward Nowton" , "Middle level", "Pigg",1},
{
"New Yorker" , "low level" , "Dude" ,2
}
};
cout << "Benavolent Order of Programmers Report:"<<endl;
cout << "a. display by name \t b.display by title \nc. display by bopname \t d. display by preference \nq. quit"<<endl;
char flag;
cout << "Enter your choice:";
while(1)
{
cin >> flag;
switch (flag)
{
case 'a':
for (int i = 0; i<3 ;i++)
{
cout << member[i].fullname<<endl;
}
break;
case 'b':
for (int i = 0; i<3 ;i++)
cout << member[i].title<<endl;
break;
case 'c':
for (int i = 0; i<3 ;i++)
cout << member[i].bopname<<endl;
break;
case 'q':
cout << "bye";
break;
}
if(flag == 'q')
break;
}
cout << "No.5"<<endl;
double income,tax;
cin >> income;
cout << fixed;
cout.setf(ios_base::showpoint);
cout.precision(2);
while(cin.good() && income > 0)
{
if(income < 5000)
cout << "tax = 0"<<endl;
else if(income > 5000&& income < 15000)
{
tax = 5000 * 0 + (income - 5000) * 0.1;
cout << "tax = "<<tax<<endl;
}
else if(income > 15000&& income <= 35000)
{
tax = 5000 * 0 + 10000 * 0.1+(income - 15000) * 0.15;
cout << "tax = "<<tax<<endl;
}
else if(income > 35000){
tax = 5000 * 0 + 10000 * 0.1+20000 * 0.15+(income - 35000) * 0.15;
cout << "tax = "<<tax<<endl;
}
cin >> income;
}
cout << "No.8"<<endl;
ifstream infile;
infile.open("carinfo.txt");
int i = 0;
infile.get();
if(!infile.is_open())
{
cout << "opening file has been failed"<<endl;
}
while(infile.good())
{
i++;
infile.get();
}
cout << i << " chars in this file"<<endl;
*/
return 0;
}