0
点赞
收藏
分享

微信扫一扫

第四章部分编程题

一叶随风_c94d 2022-02-19 阅读 101
c++

1.

#include<iostream>
#include<string>
using namespace std;

int main()
{
    string fname;
    cout<<"What is your first name? ";
    getline(cin,fname);
    string lname;
    cout<<"What is your lname? ";
    getline(cin,lname);

    cout<<"What letter grade do you deserve? ";
    char grade;
    cin.get(grade);

    cout<<"What is your age? ";
    int age;
    cin>>age;

    cout<<"Name: "<<lname<<" "<<fname<<endl;
    cout<<"Grade: "<<char(grade+1)<<endl;
    cout<<"Age: "<<age<<endl;
    return 0;
}

3.

#include<iostream>
#include<cstring>
using namespace std;

int main()
{
    char fname[20], lname[20];
    cout<<"Enter your first name: ";
    cin>>fname;
    cout<<"Enter your last name: ";
    cin>>lname;
    cout<<"Here's the information in  a single string: ";
    strcat(fname,", ");
    strcat(fname, lname);
    cout<<fname<<endl;
    return 0;
}

4.

#include<iostream>
#include<string>
using namespace std;

int main()
{
    string str1, str2;
    cout<<"Enter your first name: ";
    cin>>str1;
    cout<<"Enter your last name: ";
    cin>>str2;
    cout<<"Here's the information in  a single string: "<<str2<<", "<<str1<<endl;

    return 0;
}
举报

相关推荐

第四章编程练习

java第四章编程题(初学篇)

第四章

第四章总结

第四章:表

第四章、数组

第四章:Hbase

0 条评论