摘要: 7.1#includeusing namespace std;double tiaohe(double ,double );void main71(){ double a,b; cout>a; cin>>b; if(a==0||b==0) cout<<"\nWrong input"<<endl; else cout<<"tiaohe is "<<tiaohe(a,b)<<endl; system("pause");}double tiaohe(double 阅读全文
posted @ 2014-03-31 21:12 天下纵横C++ 阅读(150) 评论(0) 推荐(0)
摘要: string 转int string str="123";int i;i=atoi(str.c_str());cin.getline()输入最后会自动丢弃回车符cin.clear()是不会清除最后的回车符的如果想清楚最后那个回车符,必须调用一次cin.get()!关于模板类:错误 1 error C2955: “List”: 使用类 模板 需要 模板 参数列表 e:\c++\number10\number10\list.cpp6 1 number10template class List{/**/}cpp实现:template List::List() //模板类的定义必须 阅读全文
posted @ 2014-03-31 16:51 天下纵横C++ 阅读(187) 评论(0) 推荐(0)
摘要: 6.9#include #include #include using namespace std;struct donation{ string name; double num;};void main69(){ const int Size=10;//假设低于10000的少于10人 donation *p=new donation[Size]; donation *q=p; int count=0;//用于记录低于10000的人数 ifstream fin; fin.open("6t.txt"); if(!fin.is_open()) cout10000) coutna 阅读全文
posted @ 2014-03-31 16:50 天下纵横C++ 阅读(186) 评论(0) 推荐(0)
摘要: //6.8#include#includeusing namespace std;void main68(){ ifstream inFile; ifstream fin; int count=0; inFile.open("2.txt"); //请将文本文件放到当前路径 if(!inFile.is_open()) { cout>ch; while(inFile.good()) { count++; inFile>>ch; } if(inFile.eof()) { cout<<"count="<<count< 阅读全文
posted @ 2014-03-31 16:00 天下纵横C++ 阅读(149) 评论(0) 推荐(0)
摘要: 6.7#include#includeusing namespace std;void main67(){ const int Size=10; int vowels=0; //存储个数 int consonants=0; int other=0; cout>temp; cout<<temp<<" "<<endl; t=temp[0]; //int j=0; //while(t!='\0') //判断元音开头 //{ 这里我默认输入的都是单词或者数字,即不会出现如 aag125sa这类的输入 if(!isalpha( 阅读全文
posted @ 2014-03-31 15:19 天下纵横C++ 阅读(160) 评论(0) 推荐(0)
摘要: 6.6#include #include using namespace std;struct donation{ string name; double num;};void main66(){ cout>(const int number); int number; int belowW=0; //计算小于10000的人数 cin>>number; donation *p=new donation[number];//动态分配结构数组 donation *q=p; int i=0; while(i>q->name; cout>q->num; if( 阅读全文
posted @ 2014-03-31 14:27 天下纵横C++ 阅读(261) 评论(0) 推荐(0)
摘要: //6.5#include #includeusing namespace std;void main65(){ int salary; cout>salary; while(salary>=0)//&&isdigit(salary)) { if(salary>salary; } //cout<<salary<<" isdigit()"<<endl;//<<isdigit(salary)<<endl; cout<<"Finish!"; cin.get 阅读全文
posted @ 2014-03-31 13:41 天下纵横C++ 阅读(146) 评论(0) 推荐(0)
摘要: 6.4#include using namespace std;const int strsize=20;struct bop{ char fullname[strsize]; //real name char title[strsize]; //job title char bopname[strsize]; //secret BOP name int preference; //0=fullname 1=title 2=bopname};void getCout(char c,bop *b);void main64(){ bop b[4]={{"Chen shiguang&quo 阅读全文
posted @ 2014-03-31 13:19 天下纵横C++ 阅读(194) 评论(0) 推荐(0)
摘要: 6.3#include using namespace std;void main63(){ cout>ch; switch(ch) { case 'c':cout<<"A mape is a carnivore",flag=false;break; case 'p':cout<<"A mape is a pianist",flag=false;break; case 't':cout<<"A mape is a tree",flag=false 阅读全文
posted @ 2014-03-28 11:11 天下纵横C++ 阅读(174) 评论(0) 推荐(0)
摘要: //编写一个程序,最多将10个donation值读入到一个double数组中。//程序遇到非数字输入时将结束输入,并报告这些数字的平均值以//及数组中有多少个数字大于平均值。#include #include #include using namespace std;const int MAX=10;void main62(){ //double donation[MAX]; arraydonation={0}; char ch; //for(int i=0;i>temp) //程序当输入非数字时,总会异常跳出,什么原因呢? { donation[i]=temp; sum+=dona.. 阅读全文
posted @ 2014-03-28 10:53 天下纵横C++ 阅读(355) 评论(0) 推荐(0)