云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > C++面向对象程序设计教程(第3版)—-陈维兴,林小茶课后习题答案

C++面向对象程序设计教程(第3版)—-陈维兴,林小茶课后习题答案

  • 62 次阅读
  • 3 次下载
  • 2025/5/6 0:23:25

class Container {

protected:

double r, d; 如果是圆柱体,r为底面半径,d为高。如果是正方体,r为边长, d为0。 public:

Container(double a, double b = 0) {

r = a; d = b; }

virtual double serface() = 0; cerr和clog间的区别是

cerr不经过缓冲区直接显示错误信息。而clog存放在缓冲区,缓冲区满或遇上endl时再输出。

C++提供哪两种控制输入输出格式的方法

一种是使用ios类中的有关格式控制的流成员函数进行格式控制,另一种是使用称为操纵符的特殊类型的函数控制。

C++进行文件输入输出的基本过程是什么

首先创建一个流对象,然后将这个流对象与文件相关联,即打开文件,此时才能进行读写操作,读写操作完成后再关闭这个文件。 BCA

#include #include using namespace std;

int factorial(int n) {

if(n == 0 || n == 1) return n;

return factorial(n-1)*n; }

int main() {

for(int i = 1; i <= 9; i++) {

cout << setw(5) << factorial(i); if(i % 3 == 0) {

cout << endl; } }

return 0; }

#include #include using namespace std;

int main() {

for(int i = 1; i <= 7; i++) {

cout << setw(16-i);

for(int j = 1; j <= (2*i - 1); j++) {

cout << 'A'; }

cout << endl; }

return 0; }

#include #include using namespace std;

class matrix {

private:

int data[2][3]; public:

matrix(){}

friend ostream &operator<<(ostream &, matrix &); friend istream &operator>>(istream &, matrix &); friend matrix operator+(matrix &, matrix &); };

ostream &operator<<(ostream &os, matrix &a) {

for(int i = 0; i < 2; i++) {

for(int j = 0; j < 3; j++) {

os << [i][j] << \ \; }

os << endl; }

return os; }

istream &operator>>(istream &in, matrix &a) {

cout << \请输入一个2行3列矩阵:\ << endl; for(int i = 0; i < 2; i++) {

for(int j = 0; j < 3; j++) {

in >> [i][j]; } }

return in; }

matrix operator+(matrix &a, matrix &b) {

matrix temp;

for(int i = 0; i < 2; i++) {

for(int j = 0; j < 3; j++) {

[i][j] = [i][j] + [i][j]; } }

return temp; }

int main() {

matrix m1, m2, total; cin >> m1 >> m2; total = m1 + m2; cout << total; return 0; }

#include #include using namespace std;

int main() {

fstream fout(\,ios::out); if(!fout) {

cout << \文件打开失败!\ << endl; return 1; }

fout << \; fout << \; fout << \; ();

return 0; }

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

class Container { protected: double r, d; 如果是圆柱体,r为底面半径,d为高。如果是正方体,r为边长, d为0。 public: Container(double a, double b = 0) { r = a; d = b; } virtual double serface() = 0; cerr和clog间的区别是 cerr不经过缓冲区直接显示错误信息。而clog存放在缓冲区,缓冲区满或遇上endl时再输出。 C++提供哪两种控制输入输出格式的方法 一种是使用ios类中的有关格式控制的流成员函数进行格式控制,另一种是使用称为操纵符的特殊类型的函数控

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com