第1-7章C++面向对象程序设计_作业参考答案.docx
第1-7章C+面向对象程序设计_作业参考答案 第1章 1.2 重点:标准输入输出库函数标准输入输出流对象 #include int main() char name20; cout>name; coutb?c=a:c=b; return(c); long max(long a,long b) long c; a>b?c=a:c=b; return(c); double max(double a,double b) double c; a>b?c=a:c=b; return(c); 3 1.9要点:申请动态数组 / A simple example of new and delete. #include #include using namespace std; const int N=10; int main( ) char *p,q; int i=0; p=new charN; /allocate memory for a array 为数组分配动态内存空间if(p=NULL) cout>q; while(q!='#') pi+=q; cin>>q; coutai) min=ai; void main( ) int a10=2,5,3,9,0,8,1,7,6,4; int max,min; f(a,10,max,min); cout)运算符。 #include #include class Student 10 private: int number; char name15; float score; public: Student(int number1,char *name1,float score1); /构造函数的声明void modify(float score1) score=score1; void print( ); ; /构造函数的定义 Student:Student (int number1,char *name1,float score1) number=number1; strcpy(name,name1); score=score1; void Student:print( ) coutprint(); 11