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

1

#include 
#include
using namespace std;

int main()
{
    char ch;
    while(cin.get(ch) && ch != '@'){
        if(isdigit(ch)){
            continue;
        }
        else if(isupper(ch)){
            cout<

2

#include 

using namespace std;

int main()
{
    double numbers[10];
    double average=0;
    int OnAve=0;
    int i=0;
    cout<<"Enter the "<< i+1<<" number: ";
    while(i<10 && (cin>>numbers[i])){
        i++;
        cout<<"Enter the "<< i+1<<" number: ";
        average+=numbers[i-1];
    }
    average/=i;
    for(int j=0;javerage){
            OnAve++;
        }
    }
    cout<<"you enter "<

3

c++Primer Plus 第六章课后习题_第1张图片

#include 

using namespace std;

bool isSelection(char ch){
    return ch=='t' || ch=='c' || ch=='p' || ch=='g';
}

int main()
{
    cout<<"Please enter one of the following choices:"<>ch;
        if(isSelection(ch)){
            switch(ch){
            case 'c':
                cout<<"a tiger is a carnivore."<

4

c++Primer Plus 第六章课后习题_第2张图片

#include 

using namespace std;

bool isSelection(char ch){
    return ch=='a' || ch=='b' || ch=='c' || ch=='d';
}

const int strsize=50;

struct bop{
    char fullname[strsize];
    char title[strsize];
    char bopname[strsize];
    int preferrence;
    void showName(){
        cout<>ch;
        if(isSelection(ch)){
            switch(ch){
            case 'a':
                for(int i=0;i<3;i++){
                    Bop[i].showName();
                }
                break;
            case 'b':
                for(int i=0;i<3;i++){
                    Bop[i].showTitle();
                }
                break;
            case 'c':
                for(int i=0;i<3;i++){
                    Bop[i].showBopName();
                }
                break;
            case 'd':
                for(int i=0;i<3;i++){
                    Bop[i].showPreferrence();
                }
                break;
            }
        }
        else if(ch=='q'){
            break;
        }
        else{
            while(cin.get()!='\n'){
                continue;
            }
            cout<<"Please enter the corrct selection"<

5

c++Primer Plus 第六章课后习题_第3张图片

#include 

using namespace std;

int main()
{
    int tvarps;
    cout<<"Please enter your income: ";
    while(cin>>tvarps){
        double tax=0.0;
        if(tvarps<0){
            break;
        }
        if(tvarps>35000){
            tax=(tvarps-35000)*0.2+20000*0.15+10000*0.1;
        }
        else if(tvarps>15000){
            tax=(tvarps-15000)*0.15+10000*0.1;
        }
        else if(tvarps>5000){
            tax=(tvarps-5000)*0.1;
        }
        else{
            tax=0.0;
        }
        cout<<"individual income tax: "<

6

c++Primer Plus 第六章课后习题_第4张图片

#include 

using namespace std;

struct donate{
    string name;
    double money;
    void show(){
        cout<<"Name: "<>number;
    struct donate *donators=new struct donate[number];

    for(int i=0;i>(donators+i)->name;
        cout<<"Money: ";
        cin>>(donators+i)->money;
    }
    cout<<"Grand Patrons:"<money>=10000){
            (donators+i)->show();
        }
    }
    cout<<"Other Patrons:"<money<10000){
            (donators+i)->show();
        }
    }
    cout << "Hello World!" << endl;
    return 0;
}

7

c++Primer Plus 第六章课后习题_第5张图片

#include 
#include
using namespace std;

bool isVowels(char ch){
    return ch=='a' || ch=='A' || ch=='e' ||ch=='E' ||ch=='i'||ch=='I'||ch=='O'||ch=='o'||ch=='U'||ch=='u';
}


int main()
{
    cout<<"Enter words (q to quit):"<

8

 非逐字符读物文件

#include 
#include
using namespace std;

int main()
{
    ofstream of;
    int numberOfChars=0;
    of.open("demo1.txt");
    of<<"jisuanji\n jisuanji jisaunji sjaisjia";
    of.close();

    ifstream inf;
    inf.open("demo1.txt");
    if(!inf.is_open()){
        cout<<"open file erro";
        exit(EXIT_FAILURE);
    }
    string str;
    while(getline(inf,str)){
        numberOfChars+=str.length();
    }
    cout<<"number Of Chars :"<

逐字符读取文件

#include 
#include
using namespace std;

int main()
{
    ofstream of;
    int numberOfChars=0;
    of.open("demo1.txt");
    of<<"jisuanji\n jisuanji jisaunji sjaisjia";
    of.close();

    ifstream inf;
    inf.open("demo1.txt");
    if(!inf.is_open()){
        cout<<"open file erro";
        exit(EXIT_FAILURE);
    }
    char ch;
    while(inf>>ch){
        cout<

9

c++Primer Plus 第六章课后习题_第6张图片

懒得写了

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