2015年电大C++语言程序设计课程的程序分析练习题及答案资料小抄_第1页
2015年电大C++语言程序设计课程的程序分析练习题及答案资料小抄_第2页
2015年电大C++语言程序设计课程的程序分析练习题及答案资料小抄_第3页
2015年电大C++语言程序设计课程的程序分析练习题及答案资料小抄_第4页
2015年电大C++语言程序设计课程的程序分析练习题及答案资料小抄_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 电大 C+语言程序设计课程的程序分析练习题 徐孝凯 一 、写出下列每个程序运行后的输出结果 1. #include #include void main() int x=20, y=6, z; char op=+; switch(op) case +: z=x+y; break; case -: z=x-y; break; default: cout操作符 op出错,退出运行 !;exit(1); cout”z=”zendl; 运行结果: 2. #include #include void main() char* a5=student,worker,cadre,soldier,apen; unsigned int n=strlen(a0); /求字符串 a0的长度 for(int i=1;in) n=strlen(ai); coutnendl; 运行结果: 3. #include int WF(int x, int y) x=x+y; y=x+y; return x+y; void main() coutWF(8,5)endl; 运行结果: 2 4. #include const int N=9; void main() int aN=2,4,6,8,10,12,14,16,18; int s=0; for(int i=0; iN; i+) if(ai%3=0) s+=ai; cout”s=”sendl; 运行结果: 5. #include void main() int* d=new int5; int i,s=0; for(i=0;i5;i+) di=2*i+1; for(i=0;i5;i+) s+=di; cout3*sendl; deleted; 6. #include void SB(char ch) switch(ch) case A: case a: cout优 ! ; break; case B: case b: cout良 ! ; break; case C: case c: cout通过 ! ; break; default: cout不通过 !;break; void main() SB(A); SB(c); coutendl; 运行结果: 7. #include void main() int a6=36,25,48,14,55,40; int x=a0; 3 for(int i=1;ix) x=ai; cout”x=”xendl; 运行结果: 8. #include void main() int a6=32,53,27,19,12,45; for(int *p=a; pa+6; p+) if(*p%3=0) cout*p ; coutendl; 运行结果: 9. #include int* LG(int m) int* a=new int(m+5); return a; void main() int n1=12; int *b=LG(n1); cout*bendl; delete b; 运行结果: 10. #include #include struct Worker char name15; int age; float pay; ; void main() Worker x; strcpy(, WeiRong); x.age=45; x.pay=3275; x.age x.payendl; 运行结果: 4 11. #include void main() int n=5, sum=0; while(n) sum+=n; n-; cout”sum=”sumendl; 运行结果: 12. #include const int N=6; void main() int aN=76,83,54,62,40,65; int c1, c2; c1=c2=a0; for(int i=1;ic1) c1=ai; else if(aic2) c2=ai; coutc1 c2endl; 运行结果: 13. #include void main() int a8=4,8,15,16,20,30,48,62; int *p=a; while(pa+8) cout*p ; p+=3; coutendl; 运行 结果: 14.#include int LF(int x, int y) x=x+y; y=x+y; 5 return x+y; void main() int x=5, y=8; coutLF(1,2) LF(3,4)endl; 运行结果: 15. #include class A int a,b; public: A() a=b=0; A(int aa, int bb) a=aa; b=bb; couta bendl; ; void main() A x,y(3,4); 运行结果: 16. #include void main() int n=4,y=1; while(n-) y*=3; couty=yendl; 运行结果: 17. #include void main() int a8=2,8,10,5,12,7,9,20; int c=0, i=0; while(i10) c+; i+; coutc=cendl; 运行结果: 6 18. #include void main() int a5=3,6,9,12,8; for(int *p=a; p8) cout*p ; 运行结果: 19. #include int LA(int a, int n) int s=0; for(int i=0;in;i+) s+=ai; return s; void main() int a5=5,2,8,6,4; int b=LA(a,5); coutb=bendl; 运行结果: 20. #include struct AB char aa15; int bb; ; void main() AB a4=Apple,25,Peach,40,Pear,36,Tomato,62; for(int i=0;i4;i+) if(ai.bb40) coutai.aa ; coutendl; 运行结果: 21. #include void main() int s1=0; 7 for(int i=1; i=5; i+) s1+=2*i; cout”s1=”s1endl; 输出结果: 22. #include void main() int a6=6,9,12,18,15,20; int c=0; for(int i=0; i6; i+) if(ai%2=1) c+; coutc=cendl; 输出结果: 23. #include void main() int a34=1,2,7,8,5,6,11,15,9,20,3,4; int m=a00; for(int i=0;i3;i+) for(int j=0;jm) m=aij; coutmendl; 输出结果: 24. #include void main() int a=10, b=15, c; c=a+b; int b=a+20; c+=a+b; coutcendl; 输出结果: 25. #include void main() 8 int a8=6,19,4,12,20,5,18,25; int *p, s=0; for(p=a; pa+8;p+) if(*p10) s+=*p; coutsendl; 输出结果: 26. #include void main() int s=0; for(int i=1;i=8;i+=2) s+=i*i; couts=sendl; 输出结果: 27. #include void main() int i=1,s=0; while(s15) s+=i+; couti,sendl; 输出结果: 28. #include void main() int a8=36,25,48,14,55,20,47,82; int c1=0, c2=0; for(int i=0; i8; i+) if(ai50) c1+; else c2+; coutc1 c2endl; 输出结果: 29. #include int LB(int *a, int n) 9 int p=1; for(int i=0;in;i+) p*=*a; a+; return p; void main() int a5=1,2,3,4,3; coutLB(a,5)endl; 输出结果: 30. #include struct Worker char name15; /姓名 int age; /年龄 float pay; /工资 ; void main() Worker x=wangfong,46,1640; Worker y, *p; y=x; p=&x; couty.age+10 pay*2endl; 输出结果: 31. #include void main() int n=5, sum=0; while(n) sum+=n*n; n-; coutsum=sumendl; 运行结果: 32. #include const int N=6; void main() int aN=76,83,54,62,40,65; 10 int c1=0; for(int i=0;i=60) c1+; coutc1=c1endl; 运行结果: 33. #include void main() int a8=4,8,15,16,20,30,48,62; int *p=a,s=0; while(pa+8) s+=*p; p+=3; coutsendl; 运行结果: 34. #include int a=10, b=15, c; void main() c=a+b; int b=a+20; c+=a+b; coutcendl; 输出结果: 35. #include void FF(int a, int n) int i,x; for(i=0; in/2; i+) x=ai; ai=an-1-i; an-1-i=x; void main() int a8=6,19,4,12,20,5,18,25; FF(a,8); couta0,a1b) a=b; if(ac) a=c; return a; 函数功能: 2. double WA(double a, int n) double s=0; for(int i=0;in;i+) s+=ai; return s/n; 函数功能: 3. double SF(double x, int n) /n为大于等于 0的整数 double p=1,s=1; for(int i=1;i=n;i+) p*=x; s+=p/(i+1); return s; 函数功能: 4. double FI(double n) /n为大于等于 1的整数 double x,y=0; for(int i=0; ix; y+=x; return y; 函数功能: 5. int WG(int a, int b) if(a0 & b0) return 1; else if(a0 & bnext; return n; 函数功能: 7. int SA(int a, int b) if(ab) return 1; else if(a=b) return 0; else return -1; 函数 功能: 8. int LK(int a, int n) float s=0; int i; for(i=0;in;i+) s+=ai; s/=n; int m=0; for(i=0;i=s) m+; return m; 函数功能: 9. int WD(int a, int n) int m=a0; for(int i=1;im) m=ai; return m; 函数功能: 10. bool WB(int a, int n, int x) for(int i=0;in;i+) if(ai=x) return true; return false; 14 函数功能: 11. int LJ(int a, int n) int k=0; for(int i=1;iak) k=i; return ak; 函数功能: 12. 假定结构类型 DNode中的 data域为结点值域, next域为结点指针域。 void QB(DNode *f) /f指向单链表的表头结点 if(f=NULL) return; while(f!=NULL) coutdatanext; 函数功能: 13 int WC(int a, int n, int k) int c=0; for(int i=0;i=k) c+; return c; 函数功能: 14. bool SG(int x) /x为大于等于 2的整数 int a=int(sqrt(x); /sqrt(x)为求 x的平方根 int i=2; while(i=a) if(x%i=0) break; i+; if(i=a) return true; else return false; 15 函数功能: 15. 假定结构类型 Worker中的 name域表示姓名, age域表示年龄, pay域表示工资。 void QA(Worker a, int n) for(int i=0; ai.ageai.pay; 函数功能: 16. double FI(int n) /n为大于等于 1的整数 double x,y=0; do cinx; y+=x*x; while(-n); return y; 函数功能: 17. bool WE(int a, int b, int n) for(int i=0;in;i+) if(ai!=bi) break; if(i=n) return true; return false; 函数功能: 18. int LK(int a, int n) double s=0; int i,m=0; for(i=0;in;i+) s+=ai; s=s/n; for(i=0;i=s) m+; return m; 函数功能: 16 19. double FI(int n) /n为大于等于 1的整数 double x,y=0; do cinx; y+=x; while(-n); return y; 函数功能: 20. bool WE(int a, int b, int n) for(int i=0;in;i+) if(ai!=bi) break; if(i=n) return true; return false; 函数功能: 21. int LK(int a, int n) double s=0; int i,m=0; for(i=0;in;i+) s+=ai; s=s/n; for(i=0;i=s) m+; return m; 函数功能: 二 、 写 出下列每个函数的功能( 参考答案 ) 评分标准:每题与参考答案的叙述含义相同者得 8分,否则酌情给分。 1. 求出 a,b,c三个数中的最小值并返回。 2. 求出数组 a中 n个元素的平均值并返回。 3. 计算出表达式1.3221 nnxxx 的值并返回。 4. 求出并返回从键盘上输入的 n个实数之和。 5. 若 a和 b都大于 0则返回 1,若 a和 b都小于 0则返回 -1,其他任何情况则返回 0。 6. 求出并返回 f单链表的长度(即结点个数)。 7. 比较两个整数 a和 b的大小,若 ab则返回 1,若 a=b则返回 0,若 ab则返回 -1。 8. 求出数组 a的 n个元素中大于等于平均值的元素个数并返回。 9. 从数组 a的 n个元素中求出最大值并返回。 10.从数组 a中顺序查找值为 x的元素,若查找成功则返回真,否则返回假。 11.求出数组 a中 n个元素的最大值并返回。 17 12.遍历输出 f单链表中的所有结点的值。 13. 统计出数组 a的 n个元素中大于等于参数 k的值的元素个数并返回。 14. 判断 x是否为一个素数(或质数),若是则返回真,否则返回假。 15. 从键盘上输入 n个 Worker结构类型的记录依次保存到一维数组 a的对应元素中。 16.求出从键盘上输入的 n个整数的平方和并返回。 17. 判断具有 n个元素的两个数组 a和 b中对应元素值是否全部相等,若是则返回真,否则返回假。 18.统计出数组 an中大于等于其平均值的元素个数并作为函数值返回。 19.求出从键盘上输入的 n个整数的和并返回。 20. 判断具有 n个元素的两个数组 a和 b中对应元素值是否全部相等,若是则返回真,否则返回假。 21.统计出数组 an中大于等于其平均值的元素个数并作为函数值返回。 18 请您删除一下内容, O( _ )O谢谢! 2015年中央电大期末复习考 试小抄大全,电大期末考试必备小抄,电大考试必过小抄 After earning his spurs in the kitchens of The Westin, The Sheraton, Sens on the Bund, and a sprinkling of other top-notch venues, Simpson Lu fi nally got the chance to become his own boss in November 2010. Sort of. The Shanghai-born chef might not actually own California Pizza Kitchen (CPK) but he is in sole charge of both kitchen and frontof- house at this Sinan Mansionsstalwart. Its certainly a responsibility to be the head chef, and then to have to manage the rest of the restaurant as well, the 31-year-old tells Enjoy Shanghai. In hotels, for example, these jobs are strictly demarcated, so its a great opportunity to learn how a business operates across the board. It was a task that management back in sunny California evidently felt he was ready for, and a vote of confi dence from a company that, to date, has opened 250 outlets in 11 countries. And for added pressure, the Shanghai branch was also CPKs China debut. For sure it was a big step, and unlike all their other Asia operations that are franchises, they decided to manage it directly to begin with, says Simpson. Two years ago a private franchisee took over the lease, but the links to CPK headquarters are still strong, with a mainland-based brand ambassador on hand to ensure the business adheres to its ethos of creating innovative, hearth-baked pizzas, a slice of PR blurb that Simpson insists lives up to the hype. They are very innovative, he says. The problem with most fast food places is that they use the same sauce on every pizza and just change the toppings. Every one of our 16 pizza sauces is a unique recipe that has been formulated to complement the toppings perfectly. The largely local customer base evidently agrees and on Saturday and Sunday, at least, the place is teeming. The kids-eat-for-free policy at weekends is undoubtedly a big draw, as well as is the spacious second-fl oor layout overlooked by a canopy of green from Fuxing Park over the road. The company is also focusing on increasing brand recognition and in recent years has taken part in outside events such as the regular California Week. Still, the sta are honest enough to admit that business could be better; as good, in fact, as in CPKs second outlet in the popular Kerry Parkside shopping mall in Pudong. Sinan Mansions has really struggled to get the number of visitors that were envisaged when it first opened, and it hasnt been easy for any of the tenants here, adds Simpson. Were planning a third outlet in the city in 2015, and we will probably choose a shopping mall again because of the better foot traffic. The tearooms once frequented by Coco Chanel and Marcel Proust are upping sticks and coming to Shanghai, Xu Junqian visits the Parisian outpost with sweet treats. One thing the century-old Parisian tearoom Angelina has shown is that legendary fashion designer Coco Chanel not only had style and glamor but also boasted great taste in food, pastries in particular. One of the most popular tearooms in Paris, Angelina is famous for having once been frequented by celebrities such as Chanel and writer Marcel Proust. Now Angelina has packed up its French ambience, efficient service, and beautiful, comforting desserts and flown them to Shanghai. At the flagship dine-in and take-out space in Shanghai, everything mimics the original tearoom designed from the beginning of the 20th century, in Paris, the height of Belle Epoque. The paintings on the wall, for example, are exactly the same as the one that depicts the landscape of southern France, the hometown of the owner; and the small tables are intentional imitations of the ones that Coco Chanel once sat at every afternoon for hot chocolate. The famous hot chocolate, known as LAfricain, is a luxurious mixture of four types of cocoa beans imported from Africa, blended in Paris and then shipped to Shanghai. Its sinfully sweet, rich and thick as if putting a bar of melting chocolate directly on the tongue and the fresh whipped cream on the side makes a light, but equally gratifying contrast. It is also sold in glass bottles as takeaway. The signature Mont-Blanc chestnut cake consists of three parts: the pureed chestnut on top, the vanilla cream like stuffing, and the meringue as base. Get all three layers in one scoop, not only for the different textures but also various flavors of sweetness. The dessert has maintained its popularity for a century, even in a country like France, perhaps the worlds most competitive place for desserts. A much overlooked pairing, is the Paris-New York choux pastry and N226 chocolate flavored tea. The choux pastry is a mouthful of airy pecan-flavored whipped cream, while the tea, a blend of black teas from China and Ceylon, cocoa and rose petals, offers a more subtle fragrance of flowers and chocolate. Ordering these two items, featuring a muted sweetness, makes it easier for you to fit into your little black dress. Breakfast, brunch, lunch and light supper are also served at the tearoom, a hub of many cultures and takes in a mix of different styles of French cuisines, according to the management team. The semi-cooked foie gras terrine, is seductive and deceptive. Its generously served at the size and shape of a toast, while the actual brioche toast is baked into a curved slice dipped with fig chutney. The flavor, however, is honest: strong, smooth and sublime. And you dont actually need the toast for crunchiness. This is the season for high teas, with dainty cups of fine china and little pastries that appeal to both visual and physical appetites. But there is one high tea with a difference, and Pauline D. Loh finds out just exactly why it is special. Earl Grey tea and macarons are all very well for the crucial recuperative break in-between intensive bouts of holiday season shopping. And for those who prefer savory to sweet, there is still the selection of classic Chinese snacks called dim sum to satisfy and satiate. High tea is a meal to eat with eye and mouth, an in-between indulgence that should be light enough not to spoil dinner, but sufficiently robust to take the edge off the hunger that strikes hours after lunch. The afternoon tea special at Shang-Xi at the Four Seasons Hotel Pudong has just the right elements. It is a pampering meal, with touches of luxury that make the high tea session a treat in itself. Whole baby abalones are braised and then topped on a shortcrust pastry shell, a sort of Chinese version of the Western vol-au-vent, but classier. Even classier is the dim sum staple shrimp dumpling or hargow, upgraded with the addition of slivers of midnight dark truffles. This is a master touch, and chef Simon Choi, who presides unchallenged at Shang-Xi, has scored a winner again. Sweet prawns and aromatic truffles whats not to love? His masterful craftsmanship is exhibited in yet another pastry a sweet pastry that is shaped to look like a walnut, but which you can put straight into the mouth. It crumbles immediately, and the slightly sweet, nutty morsel is so easy to eat youll probably reach straight f

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论