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

1

#include 

using namespace std;

int main()
{
    string firName;
    string secNmae;
    char grade;
    int age;
    cout<<"What is your first name ?";
    getline(cin,firName);
    cout<<"What is your last name ? ";
    getline(cin,secNmae);
    cout<<"What letter grade do you deserve ? ";
    cin>>grade;
    if(grade > 'C'){
        grade='C';
    }
    cout<<"What is your age ? ";
    cin>>age;
    cout<<"Name:"<

2

#include 

using namespace std;

int main()
{
    string name;
    string dessert;
    cout<<"Enter your name:\n";
    getline(cin,name);
    cout<<"Enter your favorite dessert:\n";
    getline(cin,dessert);
    cout<<"I have some delicious "<

3

#include 
#include
using namespace std;

int main()
{
    char firName[20];
    char lastName[20];
    cout<<"Enter your first name: ";
    cin.getline(firName,20);
    cout<<"Enter your last name: ";
    cin.getline(lastName,20);
    strcat(lastName,", ");
    strcat(lastName,firName);
    cout<<"Here's a information in a single string : "<

4

#include 

using namespace std;

struct CandyBar{
    string brand; //品牌
    double weight; //重量
    int calorie; //卡路里
};
int main()
{
    struct CandyBar snack={"Mocha Munch",2.3,350}; //创建即赋值
//    snack.brand="Mocha Munch";
//    snack.weight=2.3;
//    snack.calorie=350;
    cout<<"brand : "<

5

#include 

using namespace std;


struct CandyBar{
    string brand; //品牌
    double weight; //重量
    int calorie; //卡路里

    void print(){
        cout<<"brand : "<

6

#include 

using namespace std;
struct Pizza{
    string nameOfcompany;
    double diameter;
    double weight;

    void print(){
        cout<<"披萨饼公司名:"<>pizza.diameter;
    cout<<"披萨饼重量:";
    cin>>pizza.weight;
    pizza.print();
    cout << "Hello World!" << endl;
    return 0;
}

7


#include 

using namespace std;

struct Pizza{
    string nameOfcompany;
    double diameter;
    double weight;

    void print(){
        cout<<"披萨饼公司名:"<>pizza->diameter;
    cin.get();

    cout<<"请输入披萨饼公司的名称:";
    getline(cin,pizza->nameOfcompany);

    cout<<"披萨饼重量:";
    cin>>pizza->weight;
    pizza->print();
    cout << "Hello World!" << endl;

    delete pizza;
    return 0;
}

 8

#include 

using namespace std;


struct CandyBar{
    string brand="brand"; //品牌
    double weight=0.0; //重量
    int calorie=0; //卡路里

    void print(){
        cout<<"brand : "<print();
    cout<<"\n";
    (snacks+1)->print();
    cout<<"\n";
    (snacks+2)->print();
    cout << "Hello World!" << endl;
    return 0;
}

9

#include 
#include 
using namespace std;

int main()
{
    array my_array;
    cout<<"请输入第一次40m跑的时间:";
    cin>>my_array[0];
    cout<<"请输入第二次40m跑的时间:";
    cin>>my_array[1];
    cout<<"请输入第三次40m跑的时间:";
    cin>>my_array[2];
    cout<<"次数:"<<3<

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