C++ Primer Plus (第6版)编程练习 代码-----第六章

1.
#include "stdafx.h"
#include
#include
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
char temp;
char sin[20];
   
int i=0;
cout<<"请输入字符: "<


2.

#include "stdafx.h"
#include


using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{


 double donation[10];
 double sum=0;
 int i=0;
 for(i=0;i<10;i++)
 {   
cout<<"请输入第"<>(donation[i]))
{
 sum=sum+donation[i];  
}
else
{
           cin.clear();
  break;
}
  
 
 }
 if(i==0)
 {cout<<"未输入任何数字!";}
 else
 {
  cout<


3.


char inp;
   cout<<"Please enter one of the following choices:"<>inp;
while(inp!=' ')
   {
  switch (inp)
  {
     case 'c':cout<<"A maple is a carnivore\n";break;
          case 'p':cout<<"A maple is a pianist\n";break;
     case 't':cout<<"A maple is a tree\n";break;
 case 'g':cout<<"A maple is a game\n";break;
 default:cout<<"Please enter a c, p, t,or g:" ;
      }
cin>>inp;  
 
   
  }
   
system("pause");
return 0;



4.没看懂什么意思


5.

double salary;
    double tax;
cout<<"Enter your salary: ";
cin>>salary;
while((cin>>salary))
{
 if(salary>=0&&salary<=5000)
 {
  tax=5000*0.0;
 }
 else if (salary>=5001&&salary<=15000)
 {

    tax=(salary-5000)*0.10;
 }
else if (salary>=15001&&salary<=35000)
{

  tax=10000*0.10+(salary-10000)*0.15;
}
else if(salary>=35001)
{
  tax=10000*0.10+25000*0.15+(salary-35000)*0.20;
}
 cout<<"The TAX is : "<>salary;   
} 





system("pause");
return 0;

6.

using namespace std;
struct donation
{
char name[20];
double money;


};
int _tmain(int argc, _TCHAR* argv[])
{
donation *da=new donation;

int c1=0,c2=0;
int number;
    cout<<"请输入捐赠者数目:";
cin>>number;
for(int i=0;i>da[i].money;

}
cout<<"Patrons          "<<"name      "<<"   money   "<=10000)
    {
cout<<"Grand Patrons   "<



7.


using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
char word[20];
int v=0,c=0,o=0;
cout<<"Enter words (q to quit):"<>word;
int l= strlen(word);
while(!(word[0]=='q'&&l==1))
{
if(isalpha(word[0]))
{

switch(word[0])
  { case 'A': v++;break;
    case 'a': v++;break;
case 'E': v++;break;
case 'e': v++;break;
case 'I': v++;break;
case 'i': v++;break;
    case 'O': v++;break;
case 'o': v++;break;
    case 'U': v++;break;
case 'u': v++;break;
default:c++;
  }
}
else
{
   o++;
}
 cin>>word;
 l=strlen(word);

}
cout<




8.


using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
char ch;
int count =0;
ifstream inf;
inf.open("test.txt");
inf>>ch;
while(!(inf.eof()))
{

count++;
   cout<>ch;
}
inf.close();

cout<<"the file has "<



9.


#include "stdafx.h"
#include
#include  
#include
#include
using namespace std;

 struct donation
 {
   char name[20];


   int money;
 
 };

int _tmain(int argc, _TCHAR* argv[])
{
   int number;
   donation *p=new donation[4];
   fstream inf;
   inf.open("test1.txt");
   if(!inf.is_open())
   {
     cout<<"open failed "<>number;
   
   cout<<"the donation number is : "<name,20); 
  /* cout<name<>p->money;
/*cout<money<money)>=10000)
      {
   cout<name<money<money)<10000)
      {
   cout<name<money<


你可能感兴趣的:(C++,Primer,Plus,(第6版))