第一范文网 - 专业文章范例文档资料分享平台

c++面向对象程序设计课后习题答案(谭浩强版)

来源:用户分享 时间:2025/5/15 8:22:58 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

{int num; char name[20]; double score; }; int main()

{student stud[3]={1001,\ char c[50]; int i;

ostrstream strout(c,50); for(i=0;i<3;i++)

strout<

cout<<\ istrstream strin(c,50); for(i=0;i<3;i++)

strin>>stud1[i].num>>stud1[i].name>>stud1[i].score; cout<<\ for(i=0;i<3;i++)

cout<

#include #include using namespace std; struct student

{int num; char name[20]; double score; }; int main() {int i;

student stud[3]={1001,\ char c[50];

strstream strio(c,50,ios::in|ios::out); for(i=0;i<3;i++)

strio<

cout<<\ for(i=0;i<3;i++)

strio>>stud1[i].num>>stud1[i].name>>stud1[i].score; cout<<\ for(i=0;i<3;i++)

cout<

第八章

1:

#include #include

using namespace std;

double q(double,double,double); void main()

{double a,b,c,p,x1,x2; cout<<\ cin>>a>>b>>c; p=-b/(2*a); try

{x1=p+q(a,b,c); x2=p-q(a,b,c);

cout<<\ }

catch(double d)

{cout<<\ cout<<\ }

double q(double a,double b,double c) {double disc; disc=b*b-4*a*c; if (disc<0) throw disc; return sqrt(disc)/(2*a); } 2:

#include #include using namespace std;

class Student {public:

Student(int n,string nam) {cout<<\ num=n;name=nam;}

~Student(){cout<<\ void get_data(); private: int num; string name; };

void Student::get_data() {if(num==0) throw num;

else cout<

void fun()

{Student stud1(1101,\ (); try

{Student stud2(0,\ (); }

catch(int n)

{cout<<\ }

int main()

{cout<<\ cout<<\ fun();

cout<<\ return 0; } 3:

//main file #include using namespace std; #include \ #include \

using namespace std; using namespace student1;

int main()

{Student stud1(1001,\ ();

student2::Student stud2(1102,\ (); return 0; }

//,文件名为 #include

c++面向对象程序设计课后习题答案(谭浩强版).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c3ac2t6ev9r6b8ve00zsa83uyx967u500v8d_4.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top