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;
}