综合实验二参考程序

上传人:xins****2008 文档编号:111220596 上传时间:2019-11-02 格式:DOC 页数:13 大小:80.50KB
返回 下载 相关 举报
综合实验二参考程序_第1页
第1页 / 共13页
综合实验二参考程序_第2页
第2页 / 共13页
综合实验二参考程序_第3页
第3页 / 共13页
综合实验二参考程序_第4页
第4页 / 共13页
综合实验二参考程序_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《综合实验二参考程序》由会员分享,可在线阅读,更多相关《综合实验二参考程序(13页珍藏版)》请在金锄头文库上搜索。

1、1、 设计一个字符串数组的统计工具,可以实现以下功能:(1) 统计所有大写字母的个数;(2) 统计所有小写字母的个数;(3) 将所有字母转换为大写字母;(4) 将所有字母转换为小写字母。#include #include #include void main()char c100, b100;unsigned uc, i, cnt;coutPlease input a string:endl;gets(c);docoutendl;coutThe original string is cendl;coutendl;cout* String Tool *endl;cout1. Count uppe

2、rcase letters.endl;cout2. Count lowercase letters.endl;cout3. Change all letters to uppercase.endl;cout4. Change all letters to lowercase.endl;cout0. Exituc;coutendl;switch(uc)case 1:cnt=0;for (i=0; i=A & ci=Z)cnt+;coutThe number of uppercase letters in string c is: cntendl;break;case 2:cnt=0;for (i

3、=0; i=a & ci=z)cnt+;coutThe number of lowercase letters in string c is: cntendl;break;case 3:for (i=0; i=a & ci=z)bi-=32;coutThe original string cendl;coutAfter changing all letters to uppercase, it turns to bendl;break;case 4:for (i=0; i=A & ci=Z)bi+=32;coutThe original string cendl;coutAfter chang

4、ing all letters to lowercase, it turns to bendl;coutendl;while (uc);2、 实现一个32的矩阵和23的矩阵相乘,输出计算结果。计算方式如下:#include void main()int a32, b23, c33, i, j;coutPlease input 3X2 matrix a:endl;for(i=0; i3; i+)for(j=0; j2; j+)coutaijaij;coutendl;coutMatrix a is:endl;for(i=0; i3; i+)for(j=0; j2; j+)coutaijt;cout

5、endl;coutendl;coutPlease input 2X3 matrix b:endl;for(i=0; i2; i+)for(j=0; j3; j+)coutbijbij;coutendl;coutMatrix b is:endl;for(i=0; i2; i+)for(j=0; j3; j+)coutbijt;coutendl;coutendl;coutThe product matrix is:endl;for(i=0; i3; i+)for(j=0; j3; j+)cij=ai0*b0j+ai1*b1j;coutcijt;coutendl;coutendl;3、 从键盘输入1

6、0个整数,使用选择排序法输出这10个整数升序排列的结果。#include void main()int i,j, t, a10;coutPlease input 10 numbers:endl;for(i=0; i10; i+)coutaiai;coutThe original order is:endl;for(i=0; i10; i+)coutait;coutendl;for(i=0; i9; i+)for(j=i+1; jaj)t=ai; ai=aj; aj=t;coutThe sorted order is:endl;for(i=0; i10; i+)coutait;coutendl;

7、4、 在一个多维数组中记录10个同学的学号和姓名,提供2种查找方式:(1)通过输入学号查找对应的姓名;(2)通过输入姓名查找对应的学号。学号和姓名的多维数组表示如下:学号姓名101Tom102John110Mary解法一#include #include void main()char c1128=000,No,101,Tom,102,John,103,Jerry,104,Jim,105,Mike,106,Tim,107,Bob,108,David,109,Edward,110,Fred;int i,ch;char t8;coutNumbertNameendl;for(i=1; i=10; i

8、+)coutci0tci1endl; /打印学号和姓名coutendl;docout* Look up *endl;cout1. Find name based on numberendl;cout2. Find number based on nameendl;cout0. Exitch;switch(ch)case 0: break;case 1:docoutPlease input the number, quit with 000:t;if(strcmp(t, 000)=0)break;for(i=1; i=10; i+)if(strcmp(t, ci0)=0)coutThe name

9、 of number t is: ci110)coutSorry, no such number!endl;while(true);break;case 2:docoutPlease input the name, quit with No:t;if(strcmp(t, No)=0)break;for(i=1; i=10; i+)if(strcmp(t, ci1)=0)coutThe number of name t is: ci010)coutSorry, no such name!endl;while(true);break;default:coutIllegal choice!endl;while(ch);解法二#include #include void main()char c1228=000,No,101,Tom,102,John,103,Jerry,104,Jim,105,Mike,106,Tim,107,Bob,108,David,109,Edward,110,Fred,number,name;int i,ch;char t8;coutNumbertNameendl;for(i=1;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号