【程序设计与算法(三)】测验和作业题部分答案汇总(面向对象篇)

题目来源:程序设计与算法(三)测验和作业题汇总

001:简单的swap

#include <iostream>
using namespace std;

class A
{
	public:
	int x;
	int getX() { return x; }	
};

void swap(A &a, A &b)
{
	int  tmp = a.x;
	a.x = b.x;
	b.x = tmp;
}

int main()
{
	A a,b;
	a.x = 3;
	b.x = 5;
	swap(a,b);
	cout << a.getX() << "," << b.getX();
	return 0;
}

输出:

5,3

002:难一点的swap

#include <iostream>
using namespace std;

void swap(int *&a, int *&b)
{
	int * tmp = a;
	a = b;
	b = tmp;
}

int main()
{
	int a = 3,b = 5;
	int * pa = & a;
	int * pb = & b;
	swap(pa,pb);
	cout << *pa << "," << * pb;
	return 0;
}

输出:

5,3

003:好怪异的返回值

#include <iostream>
using namespace std;

// 当函数引用时,函数可用作左值
// 函数的返回类型决定函数调用是否是左值,当调用一个返回引用的函数得到左值,其他返回类型得到右值
int &getElement (int * a, int i)
{
	return a[i];	// 返回对a[i]的引用 
}

int main()
{
	int a[] = {1,2,3};
	getElement(a,1) = 10;
	cout << a[1] ;
	return 0;
}

输出:

10

004:神秘的数组初始化

#include <iostream>
using namespace std;

int main()
{
	int * a[] = {NULL, NULL, new int, new int[6]};
	
	*a[2] = 123;
	a[3][5] = 456;
	if(! a[0] ) {
		cout << * a[2] << "," << a[3][5];
	}
	return 0;
}

输出:

123,456

005:编程填空:学生信息处理程序

描述:实现一个学生信息处理程序,计算一个学生的四年平均成绩。

要求实现一个代表学生的类,并且类中所有成员变量都是【私有的】。

补充下列程序中的 Student 类以实现上述功能。

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <cstdlib>
using namespace std;

class Student {
// 在此处补充你的代码
};

int main() {
	Student student;        // 定义类的对象
	student.input();        // 输入数据
	student.calculate();    // 计算平均成绩
	student.output();       // 输出数据
}

输入:输入数据为一行,包括:姓名,年龄,学号,第一学年平均成绩,第二学年平均成绩,第三学年平均成绩,第四学年平均成绩。其中姓名为由字母和空格组成的字符串(输入保证姓名不超过20个字符,并且空格不会出现在字符串两端),年龄、学号和学年平均成绩均为非负整数。信息之间用逗号隔开。

Tom Hanks,18,7817,80,80,90,70

输出:输出一行数据,包括:姓名,年龄,学号,四年平均成绩。信息之间用逗号隔开。

Tom Hanks,18,7817,80

题解:

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <cstdlib>
using namespace std;

class Student {
	private:
		char c;
		char name[20];
		int age;
		int num;
		int grade[5];
		double ave;
	public:
		void input()
		{
			cin.getline(name,20,',');
			cin>>age>>c>>num>>c>>grade[1]>>c>>grade[2]>>c>>grade[3]>>c>>grade[4];
		}
		void calculate()
		{
			ave=(double)(grade[1]+grade[2]+grade[3]+grade[4])/4;
		}
		void output()
		{
			cout<<name<<","<<age<<","<<num<<","<<ave;
		}

};

int main() {
	Student student;        // 定义类的对象
	student.input();        // 输入数据
	student.calculate();    // 计算平均成绩
	student.output();       // 输出数据
}

006:奇怪的类复制

只有在初始化对象的时候,才会调用构造函数或复制构造函数!

#include <iostream>
using namespace std;

class Sample {
public:
	int v;
// 在此处补充你的代码
	Sample (int x = 0): v(x) {} //类型隐式转换构造函数
	Sample (const Sample &o){
		v = o.v + 2; 
	}
};

void PrintAndDouble(Sample o)  // 形参作为实参时,会调用复制构造函数 
{
	cout << o.v;
	cout << endl;
}

int main()
{
	Sample a(5);
	Sample b = a;	// 调用复制构造函数,是初始化语句 
	PrintAndDouble(b); // 调用复制构造函数
	Sample c = 20;  // 20转换为临时对象,调用类型转换构造函数,是初始化语句 
	PrintAndDouble(c); // 调用复制构造函数
	Sample d;
	d = a;  // 不会调用复制构造函数,因为d已经初始化定义过了,是赋值语句 
	cout << d.v;
	return 0;
}

输出:

9
22
5

007:返回什么才好呢

#include <iostream>
using namespace std;

class A {
public:
	int val;
	A(int v = 123): val(v) {}  // 类型转换构造函数 
	A &GetObj(){
		return *this;
	}
};

int main()
{
	int m,n;
	A a;
	cout << a.val << endl;
	while(cin >> m >> n) {
		a.GetObj() = m;		// m转换为临时对象 
		cout << a.val << endl;
		a.GetObj() = A(n);  
		cout << a.val<< endl;
	}
	return 0;
}

输入:多组数据,每组一行,是整数 m 和 n

2 3
4 5

输出:先输出一行:123,然后,对每组数据,输出两行,第一行是m,第二行是n

123
2
3
4
5 

008:超简单的复数类

#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
class Complex {
private:
    double r,i;
public:
    void Print() {
        cout << r << "+" << i << "i" << endl;
    }
    Complex(char *s=" ")
    {
    	r=s[0]-'0';
    	i=s[2]-'0';
	}
};
int main() {
    Complex a;
    a = "3+4i"; a.Print();
    a = "5+6i"; a.Print();
    return 0;
}

输出:

3+4i
5+6i

009:哪来的输出

#include <iostream>
using namespace std;

class A {
	public:
		int i;
		A(int x) { i = x; }
// 在此处补充你的代码
		~A(){
			cout << i << endl;
		}
};

int main()
{
	A a(1);
	A * pa = new A(2);
	delete pa;
	return 0;
}

输出:

2
1

010:返回什么才好呢

(与007相同,略)

011:Big & Base 封闭类问题

#include <iostream>
#include <string>
using namespace std;

class Base {
public:
	int k;
	Base(int n):k(n) { }
};

class Big
{
public:
	int v;
	Base b;
// 在此处补充你的代码
	Big(int n):v(n), b(v) { }
};

int main()
{
	int n;
	while(cin >>n) {
		Big a1(n);
		Big a2 = a1;
		cout << a1.v << "," << a1.b.k << endl;
		cout << a2.v << "," << a2.b.k << endl;
	}
}

输入:多组数据,每组一行,是一个整数

3
4

输出:对每组数据,输出两行,每行把输入的整数打印两遍

3,3
3,3
4,4
4,4	

012:这个指针哪来的

#include <iostream>
using namespace std;

struct A
{
	int v;
	A(int vv):v(vv) { }
// 在此处补充你的代码
	const A *getPointer() const{ // 常量成员函数不能修改成员变量,返回值既可以是常量,也可以是变量 
		return this;
	}
};

int main()
{
	const A a(10);
	const A * p = a.getPointer(); // 常量对象只能调用常量成员函数 
	cout << p->v << endl;
	return 0;
}

输出:

10

013:魔兽世界之一:备战

见:【POJ C++题目】魔兽世界之一:备战

014:MyString

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

class MyString {
	char * p;
public:
	MyString(const char * s) {
		if(s) {
			p = new char[strlen(s) + 1];
			strcpy(p, s);
		}
		else
			p = NULL;
	}
	
	~MyString() { 
		if(p) delete [] p; 
	}
	
// 在此处补充你的代码
	// 深拷贝 
	void Copy (const char * s){
		if(s) {
			p = new char[strlen(s) + 1];
			strcpy(p, s);
		}
		else
			p = NULL;
	}
	
	// 深拷贝
	MyString (const MyString &o){
		if(o.p) {
			p = new char[strlen(o.p) + 1];
			strcpy(p, o.p);
		}
		else
			p = NULL;
	}
	
	// 深拷贝 
	MyString &operator = (const MyString &o){
		if (p == o.p)
			return *this;
		if (p)
			delete [] p;
		if(o.p) {
			p = new char[strlen(o.p) + 1];
			strcpy(p, o.p);
		}
		else
			p = NULL;
		return *this;
	}
	
	// 重载输出流 
	friend ostream & operator << (ostream &out, const MyString &o){
		out << o.p;
		return out;
	}
};

int main()
{
	char w1[200], w2[100];
	while(cin >> w1 >> w2) {
		MyString s1(w1), s2 = s1; // 需要实现深拷贝 
		MyString s3(NULL);
		s3.Copy(w1);
		cout << s1 << "," << s2 << "," << s3 << endl;

		s2 = w2;
		s3 = s2;
		s1 = s3;
		cout << s1 << "," << s2 << "," << s3 << endl;
	}
}

输入:多组数据,每组一行,是两个不带空格的字符串

abc def
123 456

输出:对每组数据,先输出一行,打印输入中的第一个字符串三次,然后再输出一行,打印输入中的第二个字符串三次

abc,abc,abc
def,def,def
123,123,123
456,456,456

015:看上去好坑的运算符重载

#include <iostream> 
using namespace std;

class MyInt 
{ 
	int nVal; 
	public: 
	MyInt(int n) { nVal = n ;}
// 在此处补充你的代码	
	MyInt &operator - (int n){	// 运算符重载为成员函数时,参数个数要比运算符目数少1 
		this->nVal -= n;
		return *this;
	}
	
	operator int (){	// 重载类型强制转换运算符 
		return this->nVal;
	}
}; 

int Inc(int n) {
	return n + 1;
}

int main () { 
	int n;
	while(cin >> n) {
		MyInt objInt(n); 
		objInt - 2 - 1 - 3; 
		cout << Inc(objInt);
		cout << ","; 
		objInt - 2 - 1; 
		cout << Inc(objInt) << endl;
	}
	return 0;
}

输入:多组数据,每组一行,整数n

20
30

输出:对每组数据,输出一行,包括两个整数, n-5和n-8

15,12
25,22

016:惊呆!Point竟然能这样输入输出

#include <iostream> 
using namespace std;

class Point { 
	private: 
		int x; 
		int y; 
	public: 
		Point() { };
// 在此处补充你的代码
		friend istream &operator >> (istream &in, Point &p){
			in >> p.x >> p.y;
			return in;
		}
		
		friend ostream &operator << (ostream &out, const Point &p){
			out << p.x << "," << p.y;
			return out;
		}
}; 

int main() 
{ 
 	Point p;
 	while(cin >> p) {
 		cout << p << endl;
	 }
	return 0;
}

输入:多组数据,每组两个整数

2 3
4 5

输出:对每组数据,输出一行,就是输入的两个整数

2,3
4,5

017:二维数组类

#include <iostream>
#include <cstring>
using namespace std;

class Array2 {
// 在此处补充你的代码
	private:
		int row;
		int col;
		int data[10][10];
	public:
		Array2 (int r = 0, int c = 0): row(r), col(c) {}
		
		// 应付 a[i][j] 
		int *operator [] (const int i){
			return this->data[i];
		}
		
		// 应付 a(i, j) 
		int operator () (int i, int j){
			return this->data[i][j];
		}
		
		// 应付 b = a 
		Array2 &operator = (Array2 &x){
			this->row = x.row;
			this->col = x.col;
			for(int i = 0; i < x.row; i++)
        		for(int j = 0; j < x.col; j++)
        			this->data[i][j] = x.data[i][j];
        	return *this;
		}
};

int main() {
    Array2 a(3,4);
    int i, j;
    
    for(  i = 0; i < 3; ++i )
        for(  j = 0; j < 4; j ++ )
            a[i][j] = i * 4 + j;
    for(  i = 0;i < 3; ++i ) {
        for(  j = 0; j < 4; j ++ ) {
            cout << a(i, j) << ",";
        }
        cout << endl;
    }
    
    cout << "next" << endl;
    Array2 b;     b = a;
    
    for(  i = 0; i < 3; ++i ) {
        for(  j = 0; j < 4; j ++ ) {
            cout << b[i][j] << ",";
        }
        cout << endl;
    }
    
    return 0;
}

输出:

0,1,2,3,
4,5,6,7,
8,9,10,11,
next
0,1,2,3,
4,5,6,7,
8,9,10,11,

018:别叫,这个大整数已经很简化了!

(提示:使用高精度算法)

019:全面的MyString

#include <cstdlib>
#include <iostream>
using namespace std;

int strlen (const char * s) 
{	int i = 0;
	for (; s[i]; ++i);
	return i;
}

void strcpy (char * d, const char * s)
{
	int i = 0;
	for (i = 0; s[i]; ++i)
		d[i] = s[i];
	d[i] = 0;	
}

int strcmp (const char * s1, const char * s2)
{
	for (int i = 0; s1[i] && s2[i]; ++i) {
		if (s1[i] < s2[i])
			return -1;
		else if (s1[i] > s2[i])
			return 1;
	}
	return 0;
}

void strcat (char * d, const char * s)
{
	int len = strlen(d);
	strcpy(d + len, s);
}

class MyString
{
// 在此处补充你的代码
	private:
		char *str;
	public:
		// 构造函数 
		MyString (char *s = NULL){
			if (s) {
				str = new char[strlen(s) + 1];
				strcpy(str, s);
			}
			else
				str = NULL;
		}
		
		// 复制构造函数(深拷贝) 
		MyString (const MyString &s){
			if (s.str) {
				str = new char[strlen(s.str) + 1];
				strcpy(str, s.str);
			}
			else
				str = NULL;
		}
		
		// 析构函数 
		~MyString () {
			delete [] str;
		}
		
		// 重载运算符 =(深拷贝) 
		MyString &operator = (const MyString &s){
			if (s.str == str)
				return *this;
			if (str)
				delete [] str;
			if (s.str) {
				str = new char[strlen(s.str) + 1];
				strcpy(str, s.str);
			}
			else
				str = NULL;
			return *this;
		}
		
		// 重载运算符 + (MyString + MyString, MyString + constant)
		MyString operator + (const MyString &s){
			if (str && s.str) {
				char *result = new char[strlen(s.str) + strlen(str) + 1];
				strcpy(result, str);
				strcat(result, s.str);
				return MyString(result);
			}
			else if (!str && s.str) {
				str = new char[strlen(s.str) + 1];
				strcpy(str, s.str);
				return *this;
			}
			else 
				return *this;
		}
		
		// 重载运算符 + (constant + MyString)
		friend MyString operator + (char *p, MyString &s){
			if (p && s.str) {
				char *result = new char[strlen(s.str) + strlen(p) + 1];
				strcpy(result, p);
				strcat(result, s.str);
				return MyString(result);
			}
			else if (p && !s.str) {
				s.str = new char[strlen(p) + 1];
				strcpy(s.str, p);
				return s;
			}
			else 
				return s;
		}
		
		// 重载运算符 += (MyString += MyString, MyString += constant)
		void operator += (const MyString &s){
			if (str && s.str) {
				char *result = new char[strlen(s.str) + strlen(str) + 1];
				strcpy(result, str);
				strcat(result, s.str);
				str = result;
			}
			else if (!str && s.str) {
				str = new char[strlen(s.str) + 1];
				strcpy(str, s.str);
			}
		}
		
		// 重载运算符 <
		bool operator < (const MyString &s){
			return (strcmp(str, s.str) == -1);
		}
		
		// 重载运算符 >
		bool operator > (const MyString &s){
			return (strcmp(str, s.str) == 1);
		}
		
		// 重载运算符 ==
		bool operator == (const MyString &s){
			return (strcmp(str, s.str) == 0);
		}
		
		// 重载下标 []
		char &operator [] (int i){
			return str[i];
		}
		
		// 函数对象 
		MyString operator () (int begin, int len){
			int i, j;
			char *result = new char[len+1];
			for (i = begin, j = 0; i < begin+len; ++i, ++j)
				result[j] = str[i];
			result[j] = 0;
			return MyString(result);
		}
		
		// 重载输出流 << 
		friend ostream &operator << (ostream &out, const MyString &s){
			if (s.str != NULL)
				out << s.str;
			else
				out << "";
			return out;
		}
};

int CompareString(const void * e1, const void * e2)
{
	MyString * s1 = (MyString * ) e1;
	MyString * s2 = (MyString * ) e2;
	if(*s1 < *s2)
		return -1;
	else if (*s1 == *s2)
		return 0;
	else if (*s1 > *s2)
		return 1;
}

int main()
{
	MyString s1("abcd-"), s2, s3("efgh-"), s4(s1);
	MyString SArray[4] = {"big", "me", "about", "take"};
	cout << "1. " << s1 << s2 << s3 << s4 << endl;
	
	s4 = s3;
	s3 = s1 + s3;
	cout << "2. " << s1 << endl;
	cout << "3. " << s2 << endl;
	cout << "4. " << s3 << endl;
	cout << "5. " << s4 << endl;
	cout << "6. " << s1[2] << endl;
	
	s2 = s1;
	s1 = "ijkl-";
	s1[2] = 'A' ;
	cout << "7. " << s2 << endl;
	cout << "8. " << s1 << endl;
	
	s1 += "mnop";
	cout << "9. " << s1 << endl;
	
	s4 = "qrst-" + s2;
	cout << "10. " << s4 << endl;
	
	s1 = s2 + s4 + " uvw " + "xyz";
	cout << "11. " << s1 << endl;
	
	qsort(SArray, 4, sizeof(MyString), CompareString);
	for( int i = 0; i < 4;i ++ )
		cout << SArray[i] << endl;
		
	// s1的从下标0开始长度为4的子串
	cout << s1(0, 4) << endl;
	// s1的从下标5开始长度为10的子串
	cout << s1(5, 10) << endl;
	
	return 0;
}

输出:

1. abcd-efgh-abcd-
2. abcd-
3.
4. abcd-efgh-
5. efgh-
6. c
7. abcd-
8. ijAl-
9. ijAl-mnop
10. qrst-abcd-
11. abcd-qrst-abcd- uvw xyz
about
big
me
take
abcd
qrst-abcd-

020:继承自string的MyString

(略)

021:魔兽世界之二:装备

见:【POJ C++题目】魔兽世界之二:装备

见:【POJ C++题目】魔兽世界之二:装备(简化)

022:看上去像多态

#include <iostream>
using namespace std;

class B { 
	private: 
		int nBVal; 
	public: 
		void Print() { 
			cout << "nBVal="<< nBVal << endl; 
		} 
		
		void Fun() {
			cout << "B::Fun" << endl; 
		} 
		
		B (int n) { 
			nBVal = n;
		} 
};

// 在此处补充你的代码
class D: public B{ 
	private: 
		int nDVal; 
	public: 
		void Print() { 
			B::Print(); 
			cout << "nDVal="<< nDVal << endl; 
		} 
		
		void Fun() {
			cout << "D::Fun" << endl; 
		} 
		
		D (int n): B(n * 3){ 
			nDVal = n;
		} 
};

int main() { 
	B * pb; 
	D * pd; 
	
	D d(4); 
	d.Fun(); 
	
	pb = new B(2); 
	pd = new D(8); 
	pb->Fun(); 
	pd->Fun(); 
	
	pb->Print(); 
	pd->Print(); 
	
	pb = & d; 
	pb->Fun(); 
	pb->Print(); 
	
	return 0;
}

输出:

D::Fun
B::Fun
D::Fun
nBVal=2
nBVal=24
nDVal=8
B::Fun
nBVal=12

023:Fun和Do

#include <iostream> 
using namespace std;

class A { 
	private: 
		int nVal; 
	public: 
		void Fun() 
		{ cout << "A::Fun" << endl; }; 
		void Do() 
		{ cout << "A::Do" << endl; } 
}; 

class B:public A { 
	public: 
		virtual void Do() 
		{ cout << "B::Do" << endl;} 
}; 

class C:public B { 
	public: 
		void Do( ) 
		{ cout <<"C::Do"<<endl; } 
		void Fun() 
		{ cout << "C::Fun" << endl; } 
}; 

void Call(B &p) { 
	p.Fun();	// B类没有Fun,先调用基类(A类)的同名成员函数 
	p.Do(); 	// 多态,调用哪个Do,取决于p引用了哪个类的对象 
} 

int main() { 
	C c; 
	Call(c); 
	return 0;
}

输出:

A::Fun
C::Do

024:这是什么鬼delete

#include <iostream> 
using namespace std;

class A 
{ 
	public:
		A() { }
// 在此处补充你的代码
		virtual ~A() { cout << "destructor A" << endl; }
}; 

class B:public A { 
	public: 
		~B() { cout << "destructor B" << endl; } 
}; 

int main() 
{ 
	A * pa; 
	pa = new B;  // 先调用构造函数A,再调用构造函数B 
	delete pa;   // 先调用虚析构函数B,再调用虚析构函数A(若没有加virtual,则只会调用析构函数A) 
	return 0;
}

输出:

destructor B
destructor A

025:怎么又是Fun和Do

#include <iostream>
using namespace std;

class A {
	private:
		int nVal;
	public:
		void Fun()
		{ cout << "A::Fun" << endl; };
		virtual void Do()
		{ cout << "A::Do" << endl; }
};

class B:public A {
	public:
		virtual void Do()
		{ cout << "B::Do" << endl;}
};

class C:public B {
	public:
		void Do( )
		{ cout <<"C::Do"<<endl; }
		void Fun()
		{ cout << "C::Fun" << endl; }
};

void Call(A *p) {
	p->Fun();  // p指向A时,A::Fun被调用;// p指向C时,由于是基类(A类)指针,Fun不是虚函数,所以A::Fun被调用  
	p->Do();   // p指向A时,A::Do被调用; // p指向C时,由于是基类(A类)指针,且Do是虚函数,多态,所以C::Do被调用 
}

int main() {
	Call(new A());
	Call(new C());
	return 0;
}

输出:

A::Fun
A::Do
A::Fun
C::Do

026:编程填空:统计动物数量

描述:代码填空,使得程序能够自动统计当前各种动物的数量

#include <iostream>
using namespace std;
// 在此处补充你的代码
void print() {
	cout << Animal::number << " animals in the zoo, " << Dog::number << " of them are dogs, " << Cat::number << " of them are cats" << endl;
}

int main() {
	print();
	Dog d1, d2;
	Cat c1;
	print();
	Dog* d3 = new Dog();
	Animal* c2 = new Cat;
	Cat* c3 = new Cat;
	print();
	delete c3;
	delete c2;
	delete d3;
	print();
}

输出:

0 animals in the zoo, 0 of them are dogs, 0 of them are cats
3 animals in the zoo, 2 of them are dogs, 1 of them are cats
6 animals in the zoo, 3 of them are dogs, 3 of them are cats
3 animals in the zoo, 2 of them are dogs, 1 of them are cats

题解:

#include <iostream>
using namespace std;
class Animal{
	public:
		static int number;
		Animal(){number++;}
		virtual ~Animal(){number--;}
};

class Dog:public Animal
{
	public:
		static int number;
		Dog(){number++;}
		~Dog(){number--;}
};

class Cat:public Animal
{
	public:
		static int number;
		Cat(){number++;}
		~Cat(){number--;}
};

int Dog::number = 0;
int Cat::number = 0;
int Animal::number = 0;
void print() {
	cout << Animal::number << " animals in the zoo, " << Dog::number << " of them are dogs, " << Cat::number << " of them are cats" << endl;
}

int main() {
	print();
	Dog d1, d2;
	Cat c1;
	print();
	Dog* d3 = new Dog();
	Animal* c2 = new Cat;
	Cat* c3 = new Cat;
	print();
	delete c3;
	delete c2;
	delete d3;
	print();
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 《C面向对象程序设计答案》是由谭浩强编写的一本与C语言相关的教材辅导答案。C面向对象程序设计是计算机科学中的一门重要课程,谭浩强作为资深教授和编程专家,他撰写的书籍在编程领域拥有很高的权威性。 这本教材答案为学习者提供了对应教材《C面向对象程序设计版》的习题答案和思考指导。习题是帮助学生巩固所学知识和提升编程能力的重要方式,通过对答案的学习,学生可以更好地理解并运用相关知识。学习者可以通过对比答案,分析解题思路、吸收优秀的编程风格和技巧,从而提高编程水平。 《C面向对象程序设计答案》按照教材的章节顺序,详细解答了各个章节的习题,包括程序设计题、思考题、应用题等,涵盖了从基础的语法使用到复杂的程序设计技巧,旨在帮助学生全面理解并掌握C语言的面向对象编程思想和方法。 除了提供答案,这本教材还包括了一些习题的思考指导,指导学生如何分析问题、拆解问题、确定解决步骤等。这些思考指导帮助学生培养编程思维和解决问题的能力,使他们能够独立思考和解决实际编程任务。 总之,《C面向对象程序设计答案》是一本为学习C语言面向对象程序设计的学生提供的辅助资料,它不仅提供了习题答案,还包括了思考指导,帮助学生提高编程水平和解决实际问题的能力。 ### 回答2: 《C++面向对象程序设计(第3版)》是计算机科学与技术专业学生的主要教材之一,由谭浩强编写。这本书全面介绍了C++编程语言的面向对象编程思想和相关的概念、原则与技巧。 该教材内容分为15章,首先从C++的基本概念和语法入手,然后逐渐介绍了面向对象编程的思想和实现。每章的结尾都提供了习题和答案,帮助学生巩固所学知识。 《C++面向对象程序设计(第3版)》的答案是谭浩强根据书中习题所提供的参考答案。这些答案精确明确,清晰易懂,配有详细的解释和示范代码。通过阅读和理解这些答案,学生可以加深对所学知识的理解,提高自己的编程技能。 同时,这本书还提供了大量的示例代码和实践案例,帮助学生将理论知识应用于实际的编程项目中。通过实践,学生可以更好地理解面向对象编程的思想和方法,并培养自己的分析和解决问题的能力。 总之,《C++面向对象程序设计(第3版)》是一本权威性、系统性和实用性并存的教材。通过学习这本书,学生可以全面掌握C++编程语言和面向对象编程的相关知识,提高自己的编程能力,并为将来的实际工作打下坚实的基础。 ### 回答3: 《C++面向对象程序设计》(第版)是谭浩强所著的一本教材,该教材主要介绍了C++面向对象程序设计的基本概念、语法和技巧。全书共分为10个章节,涵盖了面向对象程序设计的各个方面。 第一章介绍了C++的发展历程以及面向对象程序设计的基本概念和特点。第二章详细讲解了C++的基本语法和常用数据类型。第章重点介绍了C++中的类和对象的概念,并通过具体的示例演示了如何定义和使用类。 第四章讲解了C++的继承和派生,介绍了单继承和多继承的概念以及如何定义和使用派生类。第五章介绍了C++中的多态性,包括静态多态和动态多态的概念以及如何使用虚函数实现动态绑定。 第六章讲解了C++中的运算符重载和类型转换,通过实例说明了如何重载运算符和类型转换函数。第七章介绍了C++中的异常处理机制,讲解了异常的概念和处理方法。 第八章讲解了C++中的文件操作,包括输入输出流、文件读写以及文件指针的相关知识。第九章介绍了C++的模板和泛型编程,包括函数模板和类模板的定义和使用。 第十章介绍了C++中的标准模板库(STL),包括容器、迭代器、算法和函数对象等的使用方法。 《C++面向对象程序设计》(第版)通过简明扼要的语言和生动具体的示例,全面而深入地介绍了C++面向对象程序设计的基本概念和技巧,适合初学者学习和参考。同时,该教材也提供了丰富的练习题和案例,供读者巩固和应用所学知识。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值