p221.8

 #include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
const int SLEN = ;
struct student{
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
int getinfo(student pa[], int n);
void display1(student st);
void display2(const student *ps);
void display3(const student pa[], int n); int main(){
cout << "enter class size:";
int class_size;
cin >> class_size;
while (cin.get() != '\n')
continue;
student *ptr_stu = new student[class_size];
int entered = getinfo(ptr_stu, class_size);
for (int i = ; i < entered; i++){
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
}
display3(ptr_stu, entered);
delete[]ptr_stu;
cout << "done\n";
system("pause");
return ;
} int getinfo(student pa[], int n){
int i = , count = ;
while (i < n && *pa[i].fullname != '\0'){
cin.getline(pa[i].fullname, SLEN);
cin.getline(pa[i].hobby, SLEN);
cin >> pa[i].ooplevel;
cin.get();
count++;
i++;
}
return count;
} void display1(student st){
cout << "st.fullname" << st.fullname <<
endl << "st.hobby" << st.hobby <<
endl << "st.ooplevel" << st.ooplevel <<
endl;
} void display2(const student *ps){
cout << "ps->fullname" << ps->fullname <<
endl << "ps->hobby" << ps->hobby <<
endl << "ps->ooplevel" << ps->ooplevel <<
endl;
} void display3(const student pa[], int n){
for (int i = ; i < n; i++){
cout << "pa[i].fullname" << pa[i].fullname
<< endl << "pa[i].hobby" << pa[i].hobby
<< endl << "pa[i].ooplevel" << pa[i].ooplevel
<< endl;
}
}

p259.2

 #include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
struct candybar {
char brand[];
float weight;
int calory;
};
void assign(candybar &, char br[]="millennium munch", float w=2.85, int c=);
void show_menu(candybar&); int main(){
candybar tasty;
assign(tasty);
show_menu(tasty);
system("pause");
return ;
} void assign(candybar &delicious, char br[], float w , int c){
strcpy(delicious.brand, br);
delicious.weight = w;
delicious.calory = c;
} void show_menu(candybar&delicious){
cout << delicious.brand << endl;
cout << delicious.weight << endl;
cout << delicious.calory << endl;
}

p259.4

 #include<iostream>
#include<cstdlib>
#include<cctype>
using namespace std;
struct stringy{
char* str;
int ct;
};
void set(stringy &, const char*);
void show(const stringy &, int times = );
void show(const char*, int times = ); int main(){
stringy beany;
char testing[] = "reality isn't what it used to be.";
set(beany, testing);
show(beany);
show(beany, );
delete beany.str;
testing[] = 'D';
testing[] = 'u';
show(testing);
show(testing, );
show("Done!");
system("pause");
return ;
} void set(stringy &beany, const char* testing){
int num = strlen(testing);
beany.str = new char[num + ];
strcpy(beany.str, testing);
beany.ct = num;
} void show(const stringy &beany, int times){
for (int i = ; i < times; i++)
cout << beany.str << endl
<< beany.ct << endl;
} void show(const char* testing, int times){
for (int i = ; i < times; i++)
cout << testing << endl;
}

p260.6

 #include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
template<class T>
T maxn(T ar[], int num);
template<> char *maxn(char *pt[], int num); int main(){
int num1[];
double num2[];
cout << "enter the member of two array\n";
for (int i = ; i < ; i++)
cin >> num1[i];
for (int i = ; i < ; i++)
cin >> num2[i];
int imax = maxn(num1, );
double dmax = maxn(num2, );
cout << "imax is" << imax << endl
<< "dmax is" << dmax << endl;
char *str[];
str[] = "his eyes came round";
str[] = "it all seems very unchanged";
str[] = "which contain of old the pipes";
str[] = "yes, billy, i know";
str[] = "will you be please to dine";
char *address = maxn(str, );
cout << (int*)address << " " <<
address << endl;
system("pause");
return ;
} template<class T>
T maxn(T ar[], int num){
T max=ar[];
for (int i = ; i < num; i++)
if (max < ar[i])
max = ar[i];
return max;
} template<> char *maxn(char *pt[], int num){
int length[], i;
for (i = ; i < ; i++)
length[i] = strlen(pt[i]);
int max = length[];
for (i = ; i < ; i++)
if (max < length[i])
max = length[i];
for (i = ; i < ; i++)
if (max == length[i])
break;
return pt[i];
}

c++ primer plus 习题答案(2)的更多相关文章

  1. c++ primer plus 习题答案(1)

    c++ primer plus 习题答案用的是第五版,IDE仍然是vs2013.我只标注了题号,具体的题目找下书上对应内容吧. p110.8 #include<iostream> #inc ...

  2. c++ primer plus 习题答案(8)

    p475.2 //头文件: class Cd{ private: char *performers; char *label; int selections; double playtime; pub ...

  3. c++ primer plus 习题答案(7)

    p427.4 //头文件: #include<iostream> #ifndef STACK_H_ #define STACK_H_ typedef unsigned long Item; ...

  4. c++ primer plus 习题答案(6)

    p425.1 #include<iostream> #include<cstring> #include<cstdlib> using namespace std; ...

  5. c++ primer plus 习题答案(5)

    p333.7 #include<iostream> #include<cstring> #include<cstdlib> using namespace std; ...

  6. c++ primer plus 习题答案(4)

    p333.3 #include<iostream> #include<cstdlib> #include<cstring> #include<string&g ...

  7. c++ primer plus 习题答案(3)

    p296.3 #include<iostream> #include<cstdlib> #include<string> #include<cstring&g ...

  8. C++Primer第五版——习题答案目录

    目前正在刷<C++Primer>这本书,会在博客上记录课后习题答案,答案仅供参考. 因为水平有限,如有有误之处,希望大家不吝指教,谢谢! 目录地址 使用的系统为:win 10,编译器:VS ...

  9. 《C++Primer》第五版习题答案--第五章【学习笔记】

    <C++Primer>第五版习题答案--第五章[学习笔记] ps:答案是个人在学习过程中书写,可能存在错漏之处,仅作参考. 作者:cosefy Date: 2020/1/15 第五章:语句 ...

随机推荐

  1. ProcessBuilder 和 Runtime(转)

    ProcessBuilder.start() 和 Runtime.exec() 方法都被用来创建一个操作系统进程(执行命令行操作),并返回 Process 子类的一个实例,该实例可用来控制进程状态并获 ...

  2. 用sqlserver处理excel表格

    本来最近在研究微信公众平台的,老大临时交我个任务,把excel表格里的数据导入sql数据库,我想这so easy嘛. 没想都在上面消磨了两天... 把情况介绍下:在数据库中有如下这样结构的表(A表) ...

  3. [置顶] android利用jni调用第三方库——第二篇——编写库android程序直接调用第三方库libhello.so

    0:前言 1:本文主要作为丙方android公司的身份来写 2:作者有不对的地方,请指出,谢谢 [第一篇:android利用jni调用第三方库——编写库libhello.so] [第二篇:androi ...

  4. 【菜鸟学习Linux】-第一章-Linux环境搭建-安装VMware虚拟机

    本人菜鸟一个,刚毕业才上班2个月,现在用到Linux部署项目,这才开始学习Linux,以下是我在安装Linxu系统是遇到的一些问题,希望能给广大菜鸟们在学习的道路上提供帮助和指导,废话不多说!开工! ...

  5. Root exploit for Android (adb setuid)

    /* 本文章由 莫灰灰 编写.转载请注明出处. 作者:莫灰灰    邮箱: minzhenfei@163.com */ 1. 漏洞分析 这是个非常老的漏洞了,主要利用adb启动的时候调用setuid函 ...

  6. linux下查看文件内容cat,more,less

    1. 查看文件内容经常使用的命令 cat : 由第一行显示文件内容 tac:  从最后一行開始显示.与cat相反 nl :  文件内容和行号一起输出 more: 一页一页显示 less: 与more类 ...

  7. codefirst初尝试

    Code First 约定 借助 CodeFirst,可通过使用 C# 或Visual Basic .NET 类来描述模型.模型的基本形状可通过约定来检测.约定是规则集,用于在使用 Code Firs ...

  8. EF(ServerFirst)执行存储过程实例1(带输出参数)

    1.不含动态sql.带输出参数存储过程调用实例 a.存储过程代码: b.EF自动生成代码(包括对应ObjectResult的实体模型): c.调用存储过程代码实例:  总结: ObjectParame ...

  9. EJBCA认证系统结构及相关介绍

    写作此文的主要目的是记录下EJBCA认证系统的系统结构及相关部件作用的介绍,方便后面查阅使用.

  10. BZOJ 3277: 串/ BZOJ 3473: 字符串 ( 后缀数组 + RMQ + 二分 )

    CF原题(http://codeforces.com/blog/entry/4849, 204E), CF的解法是O(Nlog^2N)的..记某个字符串以第i位开头的字符串对答案的贡献f(i), 那么 ...