C++ 学习记录(四)

//.cpp 
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string first_name, last_name;
	char grade;
	short age;
	cout << "你叫什么名字?";
	getline(cin,first_name);
	cout << "\n你的姓氏?";
	getline(cin,last_name);
	cout << "\n你的成绩?";
	cin >> grade;
	grade += 1;
	cout << "\n你的年龄?";
	(cin >> age).get();
	cout << "姓名:" << last_name << "·" << first_name << endl;
	cout << "成绩:" << grade << endl;
	cout << "年龄:" << age << endl;
	cin.get();
	return 0;
}
//.cpp 
#include <iostream>
using namespace std;
int main()
{
	char first_name[20], last_name[20];
	char grade;
	short age;
	cout << "你叫什么名字?";
	cin.getline(first_name,19);
	cout << "\n你的姓氏?";
	cin.getline(last_name,19);
	cout << "\n你的成绩?";
	cin >> grade;
	grade += 1;
	cout << "\n你的年龄?";
	(cin >> age).get();
	cout << "姓名:" << last_name << "·" << first_name << endl;
	cout << "成绩:" << grade << endl;
	cout << "年龄:" << age << endl;
	cin.get();
	return 0;
}
//.cpp 
#include <iostream>
using namespace std;
int main()
{
	char first_name[20], last_name[20], combined[42];
	cout << "你叫什么名字?";
	cin.getline(first_name,19);
	cout << "\n你的姓氏?";
	cin.getline(last_name,19);
	strcpy(combined,last_name);
	strcat(combined,"·");
	strcat(combined,first_name);
	cout << "使用单字符串显示的姓名:" << combined << endl;
	cin.get();
	return 0;
}
//.cpp 
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string first_name, last_name;
	cout << "你叫什么名字?";
	getline(cin,first_name);
	cout << "\n你的姓氏?";
	getline(cin,last_name);
	last_name +=  "·";
	last_name +=  first_name;
	cout << "使用单字符串显示的姓名:" << last_name << endl;
	cin.get();
	return 0;
}
//.cpp 
#include <iostream>
#include <string>
using namespace std;
struct Candybar
{
	string brand;
	float weight;
	int calorie;
};
int main()
{
	Candybar snack = {"Mocha Munch", 2.3, 350};
	cout << "snack.brand = " << snack.brand << endl;
	cout << "snack.weight = " << snack.weight << endl;
	cout << "snack.caroine = " << snack.calorie << endl;
	cin.get();
	return 0;
}
//.cpp 
#include <iostream>
#include <string>
using namespace std;
struct pizza
{
	string company;
	float weight;
	float diameter;
};
int main()
{
	pizza pizza1;
	cout << "请输入披萨制作公司:" ;
	getline(cin,pizza1.company);
	cout << "\n请输入披萨直径:";
	(cin >> pizza1.diameter).get();
	cout << "\n请输入披萨重量:";
	(cin >> pizza1.weight).get();
	cout << "披萨公司:" << pizza1.company << endl;
	cout << "披萨直径:" << pizza1.diameter << endl;
	cout << "披萨重量:" << pizza1.weight << endl;
	cin.get();
	return 0;
}
//.cpp 
#include <iostream>
#include <string>
using namespace std;
struct pizza
{
	string company;
	float weight;
	float diameter;
};
int main()
{
	pizza * pizza1 = new pizza;
	cout << "请输入披萨制作公司:" ;
	getline(cin,pizza1->company);
	cout << "\n请输入披萨直径:";
	(cin >> pizza1->diameter).get();
	cout << "\n请输入披萨重量:";
	(cin >> pizza1->weight).get();
	cout << "披萨公司:" << pizza1->company << endl;
	cout << "披萨直径:" << pizza1->diameter << endl;
	cout << "披萨重量:" << pizza1->weight << endl;
	delete pizza1;
	cin.get();
	return 0;
}