摘要: 这里我要创造一个Sales_item类,用来保存销售记录,要求有以下几个字段:1.isbn 商品的ISBN号2.units_sold 销量3.revenue 总价接下来我们需要以下几个函数:1.avg_price() 计算单价2.same_isbn() 用来判断两个商... 阅读全文
posted @ 2014-05-07 20:15 庄浩 阅读(147) 评论(0) 推荐(0) 编辑
摘要: //练习使用结构体#include #include #define N 5//声明一个学生结构体struct student{ char id[6]; char name[8]; int score;} stu[N];//输入学生成绩void in... 阅读全文
posted @ 2014-05-07 12:01 庄浩 阅读(269) 评论(0) 推荐(0) 编辑
摘要: 经典之一,比较简单,C语言中字符串用char数组表示,以'\0'作为结尾,请看大屏幕://计算一个字符串的长度#include #include int main(){ char str[20]; char *p; int cnt =0; //... 阅读全文
posted @ 2014-05-07 10:50 庄浩 阅读(278) 评论(0) 推荐(0) 编辑
摘要: 这里我们实现一个简单的约瑟夫环问题,描述如下:有N个人站成一圈,从第一个人开始报数,从1报到3,报到3的那个人走出圈,然后从下一个人开始从1继续报数,重复上面的过程,直到最后圈里只剩下一个人,问这个人是哪个人?分析:首先,我们要给这N个人编号,分别编为1到N,然后,开... 阅读全文
posted @ 2014-05-07 09:25 庄浩 阅读(580) 评论(0) 推荐(0) 编辑
摘要: //读取一段文本 并将他们转化为大写字母#include #include #include #include using namespace std;int main(){ vector svec; string sval; //读取一段文本 ... 阅读全文
posted @ 2014-05-04 23:28 庄浩 阅读(135) 评论(0) 推荐(0) 编辑
摘要: //连接多个string对象#include #include using namespace std;int main(){ string str,result_str; //读入多个string对象并进行连接 cout>str) r... 阅读全文
posted @ 2014-05-04 23:23 庄浩 阅读(136) 评论(0) 推荐(0) 编辑
摘要: //读取一组整数到vector 并计算头尾元素的和#include #include using namespace std;int main(){ vector ivec; int ival; //读取整数 cout ::size_type ... 阅读全文
posted @ 2014-05-04 23:10 庄浩 阅读(98) 评论(0) 推荐(0) 编辑
摘要: //读一组整数到vector对象 计算并输出每对相邻元素的和#include #include using namespace std;int main(){ vector ivec; int ival; //读取整数 cout > ival)... 阅读全文
posted @ 2014-05-04 23:08 庄浩 阅读(110) 评论(0) 推荐(0) 编辑
摘要: //去掉string对象中的标点符号#include #include using namespace std;int main(){ string str, result_str; bool has_punct = false; //用于记录有无标点 ... 阅读全文
posted @ 2014-05-04 23:00 庄浩 阅读(172) 评论(0) 推荐(0) 编辑
摘要: //判断两个字符串的大小和长度#include #include using namespace std;int main(){ string s1,s2,msg; string::size_type len1,len2; cout>s1>>s2; ... 阅读全文
posted @ 2014-05-04 22:57 庄浩 阅读(211) 评论(0) 推荐(0) 编辑