Primer_Four
来源:互联网 发布:组织结构图画图软件 编辑:程序博客网 时间:2024/05/21 16:57
#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