1、
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
char name1[20];
string name2;
char grade;
int age;
cout << "What is your first name?";
cin.getline(name1,20);
cout << "What is your last name?";
cin >> name2;
cout << "What letter grade do you deserve?";
cin >> grade;
cout << "What is your age?";
cin >> age;
cout << "Name: " << name2 << ", "<< name1 << endl;
cout << "Grade: " << char(grade + 1) << endl;
cout << "Age: " << age << endl;
}
2、
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string name;
string dessert;
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 << ".\n";
return 0;
}
3、
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
char name1[256];
char name2[256];
cout << "Enter your first name: ";
cin.getline(name1, 256);
cout << "Enter your last name: ";
cin.getline(name2, 256);
cout << "Here's the information in a single string: " << name2 << ", " << name1 << endl;
return 0;
}
4、
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string name1;
string name2;
cout << "Enter your first name: ";
cin >> name1;
cout << "Enter your last name: ";
cin >> name2;
cout << "Here's the information in a single string: " << name2 << ", " << name1 << endl;
return 0;
}
5、
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct CandyBar {
char name[30];
double weight;
int kaluli;
}snack;
int main()
{
CandyBar snack = {
"Mocha Munch",
2.3,
250
};
cout << snack.name <<endl<< snack.weight <<endl<< snack.kaluli << endl;
}
6、
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct CandyBar {
char name[30];
double weight;
int kaluli;
}snack;
int main()
{
CandyBar snack[3] = {
{"Mocha Munch",2.3,250},
{ "Bana Chu",3.4,360 },
{ "Kelvin Jay",4.7,630}
};
for(int i=0;i<3;i++)
cout << snack[i].name <<endl<< snack[i].weight <<endl<< snack[i].kaluli << endl;
}
7、
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Pizza {
char name[100];
float length;
float weight;
}temp;
int main()
{
Pizza temp;
cout << "Enter the pizza company name: ";
cin.getline(temp.name,100);
cout << "Enter the pizza length: ";
cin>>temp.length;
cout << "Enter the pizza weight: ";
cin>>temp.weight;
cout << "The company name of pizza is " << temp.name << ", the size of the pizza is " << temp.length << ", the weight of the pizza is " << temp.weight << endl;
return 0;
}
8、
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Pizza {
char name[100];
float length;
float weight;
}temp;
int main()
{
Pizza *temp=new Pizza;
cout << "Enter the pizza length: ";
cin>>temp->length;
cin.get();
cout << "Enter the pizza company name: ";
cin >> temp->name;
cout << "Enter the pizza weight: ";
cin >> temp->weight;
cout << "The company name of pizza is " << temp->name << ", the size of the pizza is " << temp->length << ", the weight of the pizza is " << temp->weight << endl;
delete temp;
return 0;
}
9、
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct CandyBar {
char name[30];
double weight;
int kaluli;
}snack;
int main()
{
CandyBar *a1 = new CandyBar[3]{
{ "Mocha Munch", 2.3, 250 },
{ "Bana Chu",3.4,360 },
{ "Kelvin Jay",4.7,630 }
};
for (int i = 0; i<3; i++)
cout << "the infomation of CandyBar, Name: " << a1[i].name << ", Weight: " << a1[i].weight << ", " << " Calories: " << a1[i].kaluli << "." << endl;
delete[]a1;
}
10、
#include "stdafx.h"
#include <iostream>
#include <array>
using namespace std;
int main()
{
array<double, 3>a1;
double avg = 0.0;
cout << "Enter the three scores: ";
cin >> a1[0];
cin >> a1[1];
cin >> a1[2];
avg = (a1[0] + a1[1] + a1[2]) / 3;
cout << "Result: " << a1[0]<<", " << a1[1] <<", "<< a1[2] << endl;
cout << "Average Result: " << avg << endl;
return 0;
}