c++Primer Plus 第五章课后习题

1

#include 

using namespace std;

int main()
{
    int num1,num2;
    cin>>num1>>num2;
    int sum=0;
    for(int i=num1;i<=num2;i++){
        sum+=i;
    }
    cout<

2

#include 
#include
using namespace std;

int main()
{
    const int arraySize=16;
    array factorials;
    factorials[0]=factorials[1]=1;
    for(int i=2;i

3

#include 

using namespace std;

int main()
{
    int sum=0;
    int number;
    cin>>number;
    while(number!=0){
        sum+=number;
        cin>>number;
    }
    cout<<"sum = "<

4

#include 

using namespace std;

int main()
{
    int sumOfd=100;
    int sumOfc=100;
    int year=0;
    while(sumOfc<=sumOfd){
        sumOfd+=10;
        sumOfc+=(sumOfc*0.05);
        year++;
    }

    cout<

5

#include 

using namespace std;

int main()
{
    string months[12] =
    {" Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","sep","Oct","Nov","Dec"};
    int num[12]={0};
    int sum=0;
    for(int i=0;i<12;i++){
        cout<>num[i];
        sum+=num[i];
    }

    cout<<"sum = "<

6

#include 

using namespace std;

int main()
{
    string months[12] =
    {" Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","sep","Oct","Nov","Dec"};
    int num[3][12]={0};
    int sum[3]={0};
    for(int i=0;i<3;i++){
        cout<<"the "<>num[i][j];
            sum[i]+=num[i][j];
        }
        cout<<"sum of the "<

7

#include 

using namespace std;

struct car{
    string produser;
    int yearOfproduce;
};

int main()
{
    int numberOfcar;
    cout<<"How many cars do you wish to catalog? ";
    cin>>numberOfcar;
    cin.get();
    struct car *cars=new struct car[numberOfcar];
    for(int i=0;iproduser);
        cout<<"Please enter the year make: ";
        cin>>(cars+i)->yearOfproduce;
        cin.get();
    }
    cout<<"Here is your collection:"<yearOfproduce;
        cout<<" "<<(cars+i)->produser<

8

#include 
#include

using namespace std;

int main()
{
    char ch[20];
    cout<<"Enter words (to stop, type the word done) :"<>ch;
    int count=0;
    while(strcmp(ch,"done")){
        count++;
        cin>>ch;
    }
    cout<<"you enter a total of 7 words"<

9

#include 
#include
using namespace std;

int main()
{
    string str;
    int count=0;
    cout<<"Enter words (to stop, type the word done) :"<>str;
    while(str!="done"){
        count++;
        cin>>str;
    }
    cout<<"you enter a total of "<

10

#include 

using namespace std;

int main()
{
    int number;
    cout<<"Enter number of rows: ";
    cin>>number;
    for(int i=0;i

你可能感兴趣的:(c语言入门+进阶,c++,算法,开发语言)