C++Primer Plus 中文版第六版课后题第九章内存模型与名称空间

时间:2019-05-15 09:40:01下载本文作者:会员上传
简介:写写帮文库小编为你整理了多篇相关的《C++Primer Plus 中文版第六版课后题第九章内存模型与名称空间》,但愿对你工作学习有帮助,当然你在写写帮文库还可以找到更多《C++Primer Plus 中文版第六版课后题第九章内存模型与名称空间》。

第一篇:C++Primer Plus 中文版第六版课后题第九章内存模型与名称空间

1. golf.h const int Len = 40;struct golf {

};void setgolf(golf & g, const char * nane, int hc);int setgolf(golf & g);void handicap(golf & g, int hc);void showgolf(const golf & g);golf.cpp char fullname[Len];int handicap;#include #include “golf.h”

using namespace std;

void setgolf(golf & g, const char * name, int hc){

}

int setgolf(golf & g){ cout << “Enter Golfers' fullname ”;cin.get(g.fullname, Len);strncpy_s(g.fullname, name, Len);g.handicap = hc;

} if(g.fullname[0] == '')return 0;cout << “Enter Golfers' handicap ”;while(!(cin >> g.handicap)){

} cin.get();return 1;cin.clear();while(cin.get()!= 'n')continue;cout << “Please enter an integer: ”;void handicap(golf & g, int hc){ }

void showgolf(const golf & g){ } main.cpp #include #include “golf.h”

using namespace std;cout << “Fullname : ” << g.fullname << “, Handicap : ” << g.handicap << endl;g.handicap = hc;const int Men = 5;int main(){

} 2.#include #include using namespace std;void strcount(const string);int main(){ string input;cout << “Enter a line: ”;golf Golfer[Men];int i;//方¤?便À?下?面?读¨¢取¨? for(i = 0;i < Men;i++){

} for(int j = 0;j < i;j++)// int i 的Ì?作Á¡Â用®? showgolf(Golfer[j]);if(setgolf(Golfer[i])== 0)break;golf ann;setgolf(ann, “Ann Birdfree”, 24);showgolf(ann);handicap(ann, 22);showgolf(ann);return 0;

} getline(cin, input);while(input!= “"){

} cout << ”Bye“ << endl;return 0;strcount(input);cout << ”Enter next line: “ << endl;getline(cin, input);void strcount(const string str){

} 3.static int total = 0;int count;cout << ”“" << str << ”“ contains ”;count = str.size();total += count;cout << count << “ characters.” << endl;cout << total << “ total characters.” << endl;#include #include using namespace std;struct chaff { char dross[20];int slag;};int main(){

} 4.sales.h chaff * p = new chaff[2];strcpy_s(p[0].dross, “Good”);p[0].slag = 23;strcpy_s(p[1].dross, “Great”);p[1].slag = 233;for(int i = 0;i < 2;i++)cout << “#” << i+1 <<“ dross: ” << p[i].dross << “, slag: ” << p[i].slag << endl;return 0;namespace SALES {

const int QUARTERS = 4;struct Sales {

};void setSales(Sales & s, const double ar[], int n);void setSales(Sales & s);void showSales(const Sales & s);double sales[QUARTERS];double average;double max;double min;} sales.cpp #include #include“sales.h” namespace SALES {

{

} static double salesmax(const double arr[], unsigned arrsize){

} static double salesmin(const double arr[], unsigned arrsize)double max = arr[0];for(int i =1;i < arrsize;i++){

} return max;if(max < arr[i])else max;max = arr[i];double sum = 0;for(int i = 0;i < arrsize;i++)sum += arr[i];return(sum/arrsize);using std ::cout;using std ::cin;using std ::endl;static double salesaverage(const double arr[], int arrsize){

} void setSales(Sales & s, const double ar[], int n){

} void setSales(Sales & s){

cout << “Enter 4 sales: ” << endl;for(int i = 0;i < QUARTERS;i++){ cout << “# ” << i+1 << “ : ”;cin >> s.sales[i];unsigned times = n < QUARTERS ?(unsigned)n:QUARTERS;for(int i = 0;i < times;i++)s.sales[i] = ar[i];s.sales[i] = 0;for(int i = times;i < QUARTERS;i++)s.average = salesaverage(s.sales, times);s.max = salesmax(s.sales, times);s.min = salesmin(s.sales, times);double min = arr[0];for(int i =1;i < arrsize;i++){

} return min;if(min > arr[i])else min;min = arr[i];

} } s.average = salesaverage(s.sales, QUARTERS);s.max = salesmax(s.sales, QUARTERS);s.min = salesmin(s.sales, QUARTERS);void showSales(const Sales & s){

} } main.cpp #include #include“sales.h” using namespace std;int main(){

using namespace SALES;Sales A, B;double hc[4] = {1.2, 2.3, 3.4, 4.5};cout <<“Show A” << endl;setSales(A, hc, 5);cout << “Sales: ” << endl;for(int i = 0;i < QUARTERS;i++){ } cout << “average: ” << s.average << endl;cout << “max: ” << s.max << endl;cout << “min: ” << s.min << endl;cout << “# ” << i+1 << “ : ” << s.sales[i] <

} showSales(A);cout <<“Show B” << endl;setSales(B);showSales(B);return 0;

下载C++Primer Plus 中文版第六版课后题第九章内存模型与名称空间word格式文档
下载C++Primer Plus 中文版第六版课后题第九章内存模型与名称空间.doc
将本文档下载到自己电脑,方便修改和收藏,请勿使用迅雷等下载。
点此处下载文档

文档为doc格式


声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:645879355@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。

相关范文推荐