4.7

1

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
//#include<cmath>
//#include<string>
using namespace std;
char name1[20], name2[20];
char gd;
int age;
int main()
{
    cout << "What is your first name ?";
    cin.getline(name1, 20);
    cout << "What is your last name ?";
    cin.getline(name2, 20);
    cout << "What letter grade do you deserve ?";
    cin >> gd;
    cout << "what is your age ?";
    cin >> age;
    cout << "Name : " << name2 << "," << name1 << endl;
    cout << "Grade : " << char(gd +1) << endl;
    cout << "Age : " << age << endl;
    return 0;

}

2

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
//#include<cmath>
#include<string>
using namespace std;
string name;
string dessert;
int main()
{
    cout << "Enter your name :\n";
    getline(cin, name);
    cout << "Enter your favorite dessert :\n";
    getline(cin, dessert);
    cout << "I have some delicious " << dessert;
    cout << " for you, " << name << endl;
    return 0;
}

3

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
//#include<string>
#include<cstring>
using namespace std;
char f_name[20];
char l_name[20];
int main()
{
    cout << "Enter your first name :";
    cin.getline(f_name, 10);
    cout << "Enter your last name :";
    cin.getline(l_name, 10);
    strcat_s(l_name, ",");
    strcat_s(l_name, f_name);
    cout << "Here's the information in a single string : " << l_name << endl;
    return 0;
}

4

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
#include<string>
//#include<cstring>
using namespace std;
string f_name;
string l_name;
int main()
{
    cout << "Enter your first name :";
    getline(cin, f_name);
    cout << "Enter your last name :";
    getline(cin, l_name);
    l_name += ',';
    l_name += f_name;
    cout << "Here's the information in a single string : " << l_name << endl;
    return 0;
}

5

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
#include<string>
//#include<cstring>
using namespace std;
struct CandyBar {
    char brand[20];
    float weight;
    int calorie;
};
int main()
{
    CandyBar snack
    {
        "Mocha Munch",
        2.3,
        350
    };
    cout << "brand : " << snack.brand << endl;
    cout << "weight : " << snack.weight << endl;
    cout << "calorie : " << snack.calorie << endl;
    system("pause");
    return 0;
}

6

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
#include<string>
//#include<cstring>
using namespace std;
struct CandyBar {
    char brand[20];
    float weight;
    int calorie;
};
int main()
{
    CandyBar snack[3]
    {
    {"Mocha Munch",2.3,350},
    {"Shang Hao Jia",3.3,520},
    {"He Shi",1.2,275} 
    };
    cout << snack[0].brand << endl;
    cout << snack[0].weight << endl;
    cout << snack[0].calorie << endl;
    cout << snack[1].brand << endl;
    cout << snack[1].weight << endl;
    cout << snack[1].calorie << endl;
    cout << snack[2].brand << endl;
    cout << snack[2].weight << endl;
    cout << snack[2].calorie << endl;
    system("pause");
    return 0;
}

7

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
//#include<string>
//#include<cstring>
using namespace std;
struct Pazz {
    char Brand[20];
    float D;
    int W;
};

int main()
{
    int i,j;
    Pazz mes[20]
    {
    };
    cin >> j;
    cin.get();
    for (i = 1; i <= j; i++)
    {
        cin.get(mes[i].Brand, 20);
        //cin >> mes[i].Brand;
        cin.get();
        cin >> mes[i].D;
        cin.get();
        cin >> mes[i].W;
        cin.get();
    cout << mes[i].Brand << endl;
    cout << mes[i].D << endl;
    cout << mes[i].W << endl;
    };
    system("pause");
    return 0;
}

 

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值