C++ Primer Plus 第六版 第四章编程练习记录
2017-07-04 21:17
519 查看
第4章(VS2013)
3.
#include<iostream>
#include<cstring>
int main()
{
using namespace std;
char fn[10];
cout << "Enter your first name: ";
cin >> fn;
char ln[10];
cout << "Enter your last name: ";
cin >> ln;
strcat_s(fn, ", ");
char he[20];
strcpy_s(he,fn);
strcat_s(he, ln);
cout << "Here's the information in a single string: "<<he << endl;
cin.get(); cin.get(); return 0; }
4.
5.
6.
7或8.
9.
#include<iostream>
struct CandyBar
{
char kind[20];
double weights;
int k;
};
int main()
{
using namespace std;
CandyBar* p = new CandyBar[3];
p[0] = { "Mocha Much", 2.3, 350 };
p[1] = { "BuLaoLin", 2.0, 400 };
p[2]={"DaBaiTu", 2.6, 300 };
for (int i = 0; i < 3; i++)
{
cout << "kind: " << p[i].kind << endl;
cout << "weights: " << p[i].weights << endl;
cout << "calorie: " << p[i].k << endl;
}
delete[] p;
cin.get();
return 0;
}
9.
#include<iostream>
#include<array>
int main()
{
using namespace std;
cout << "Please input thtee grades in seconds\n";
array<float, 3>a;
cin >> a[0];
cin >> a[1];
cin >> a[2];
8e73
cout << "first " << a[0]<<" s"<<endl;
cout << "second " << a[1] << " s" << endl;
cout << "thred " << a[2] << " s" << endl;
cout << "avgave: " << (a[0] + a[1] + a[2]) / 3 <<" s"<< endl;
cin.get(); cin.get(); return 0; }
3.
#include<iostream>
#include<cstring>
int main()
{
using namespace std;
char fn[10];
cout << "Enter your first name: ";
cin >> fn;
char ln[10];
cout << "Enter your last name: ";
cin >> ln;
strcat_s(fn, ", ");
char he[20];
strcpy_s(he,fn);
strcat_s(he, ln);
cout << "Here's the information in a single string: "<<he << endl;
cin.get(); cin.get(); return 0; }
4.
#include<iostream> #include<string> int main() { using namespace std; string str1, str2; cout << "Enter your first name: "; cin >> str1; cout << "Enter your last name: "; cin >> str2; string str; str = str2 + ", "; str = str + str1; cout << "Here's the information in a single string: " << str << endl; cin.get(); cin.get(); return 0; }
5.
#include<iostream> struct CandyBar { char kind[20]; double weights; int k; }; int main() { using namespace std; CandyBar snack = { "Mocha Much", 2.3, 350 }; cout << "kind: " << snack.kind << endl; cout << "weights: " << snack.weights << endl; cout << "calorie: " << snack.k << endl; //cin.get(); cin.get(); return 0; }
6.
#include<iostream> struct CandyBar { char kind[20]; double weights; int k; }; int main() { using namespace std; CandyBar snack[3] = { { "Mocha Much", 2.3, 350 }, {"BuLaoLin",2.0,400}, {"DaBaiTu",2.6,300} }; for (int i = 0; i < 3; i++) { cout << "kind: " << snack[i].kind << endl; cout << "weights: " << snack[i].weights << endl; cout << "calorie: " << snack[i].k << endl; } //cin.get(); cin.get(); return 0; }
7或8.
#include<iostream> struct Piza { char CompName[20]; double d; double weights; }; int main() { using namespace std; Piza* p = new Piza; cin.getline(p->CompName,20); cin >> (*p).d; cin >> p->weights; cout << "CompName: " << p->CompName << endl; cout << "d: " << p->d << endl; cout << "weights: " << p->weights << endl;
delete p;
cin.get(); cin.get(); return 0; }
9.
#include<iostream>
struct CandyBar
{
char kind[20];
double weights;
int k;
};
int main()
{
using namespace std;
CandyBar* p = new CandyBar[3];
p[0] = { "Mocha Much", 2.3, 350 };
p[1] = { "BuLaoLin", 2.0, 400 };
p[2]={"DaBaiTu", 2.6, 300 };
for (int i = 0; i < 3; i++)
{
cout << "kind: " << p[i].kind << endl;
cout << "weights: " << p[i].weights << endl;
cout << "calorie: " << p[i].k << endl;
}
delete[] p;
cin.get();
return 0;
}
9.
#include<iostream>
#include<array>
int main()
{
using namespace std;
cout << "Please input thtee grades in seconds\n";
array<float, 3>a;
cin >> a[0];
cin >> a[1];
cin >> a[2];
8e73
cout << "first " << a[0]<<" s"<<endl;
cout << "second " << a[1] << " s" << endl;
cout << "thred " << a[2] << " s" << endl;
cout << "avgave: " << (a[0] + a[1] + a[2]) / 3 <<" s"<< endl;
cin.get(); cin.get(); return 0; }
相关文章推荐
- C++ Primer Plus(第六版)第四章编程练习参考答案
- C++ Primer Plus第六版 第四章 编程练习答案
- C++ Primer Plus第六版编程练习8.2解答
- C++ Primer Plus第六版编程练习9.1解答
- C++ Primer Plus第六版编程练习10.6解答
- c++ primer plus(第6版)中文版 第四章编程练习答案
- C++ Primer Plus第六版编程练习12.4解答
- C++ Primer Plus第六版编程练习8.6解答
- C++ Primer Plus第六版编程练习10.5解答
- C++ Primer Plus第六版编程练习10.4解答
- C++ Primer Plus第六版编程练习11.5解答
- c++ primer plus 第六版第二章编程练习答案
- C++ Primer Plus第六版 第二章 编程练习答案
- C++ Primer Plus第六版编程练习12.2解答
- C++ Primer Plus第六版 第七章 编程练习答案
- C++ Primer Plus第六版编程练习10.3解答
- C++ Primer Plus第六版编程练习6.7解答
- C++ Primer Plus第六版编程练习6.9解答
- C++ Primer Plus第六版编程练习11.6解答
- C++ Primer Plus第六版编程练习11.7解答