Primer_Four

#include <iostream>
using namespace std;
int main ()
{
   const int Size=10;
   char f_name[Size],l_name[Size],grade[Size], age[Size];
   cout << "What is your first name?"<<endl;
   cin.getline(f_name,Size);
   cout << "What is your last name?"<<endl;
   cin >> l_name;
   cout << "What letter grade do you deserve?"<< endl;
   cin >> grade;
   cout << "What is your age?"<<endl;
   cin >> age;
   grade[0]=(int)grade[0]+1;
   cout << "Name: "<<l_name<<", "<<f_name<<endl;
   cout << "Grade: "<<grade<< endl;
   cout << "Age: "<< age <<endl;
   return 0;}

#include <iostream>
#include <string>
using namespace std;
int main ()
{
   string f_name,l_name,grade, age;
   cout << "What is your first name?"<<endl;
   getline(cin,f_name);
   cout << "What is your last name?"<<endl;
   cin >> l_name;
   cout << "What letter grade do you deserve?"<< endl;
   cin >> grade;
   cout << "What is your age?"<<endl;
   cin >> age;
   grade[0]=(int)grade[0]+1;
   cout << "Name: "<<l_name<<", "<<f_name<<endl;
   cout << "Grade: "<<grade<< endl;
   cout << "Age: "<< age <<endl;
   return 0;


}


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

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

#include <iostream>
using namespace std;
struct CandyBar
{
    char brand[20];
    float weight;
    int calories;
}
;



int main ()
{
    CandyBar snack=
    {
        "Mocha Munch",
        2.3,
        350
    };
    cout << "The brand is "<< snack.brand << endl;
    cout << snack.calories << " calorise" << endl;
    cout << snack.weight << " pound" << endl;
    return 0;

}

#include <iostream>
using namespace std;
struct pizza
{
    char name[20];
    float dia;
    float weight;
};

int main()
{
    pizza example;
    cout << "Please enter the pizza company name: "<<endl;
    cin.getline(example.name,20);
    cout << "Please enter the diameter of pizza:" << endl;
    cin >> example.dia;
    cout << "Please enter the weight of pizza :" << endl;
    cin >> example.weight;
    cout << "name: "<<example.name<<endl;
    cout << "diameter: "<< example.dia << endl;
    cout << "weight: " << example.weight<< endl;
    return 0;
}

#include <iostream>
using namespace std;
struct pizza
{
    char name[20];
    float dia;
    float weight;
};

int main()
{
    pizza *example=new pizza;//分配内存
    cout << "Please enter the diameter of pizza:" <<endl;
    cin >> (*example).dia;
    cin.get();
    cout << "Please enter the pizza company name: "<<endl;
    cin.get((*example).name,20);
    cout << "Please enter the weight of pizza :" <<endl;
    cin >> (*example).weight;
    cout << "name: "<<(*example).name<<endl;
    cout << "diameter: "<< (*example).dia << endl;
    cout << "weight: " << (*example).weight<< endl;
    delete example;//释放内存
    return 0;
}
//使用new创建动态结构


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值