C++面向对象习题
刘哩子不会写代码
这个作者很懒,什么都没留下…
展开
-
C++面向对象的编程-习题11(数组的初始化及使用+特殊符号的重载)
1·题目介绍2·参考程序#include<iostream>using namespace std;class Repeat{private: int a[3];public: Repeat(){} Repeat(int *p) { int i; for (i = 0; i < 3; i++) { a[i] = p[i]; } } Repeat operator^(Repeat& t) { int b[3]; int i,原创 2021-06-14 09:40:15 · 132 阅读 · 0 评论 -
C++面向对象的编程-习题10(继承习题)
1·题目介绍2·我的回答#include<iostream>#include<cmath>using namespace std;class Point{protected: int x1; int y1;public: Point(int a, int b) { x1 = a; y1 = b; }};class Line:public Point {protected: int x2; int y2;public: Line(in原创 2021-06-13 09:28:52 · 616 阅读 · 1 评论 -
C++面向对象的编程-练习9(数组指针强制转换)
1·题目介绍2·参考程序#include<iostream>#include<cstring> using namespace std;class String_Integer{private: char* s;public: String_Integer(char* str) { s = new char[strlen(str) + 1]; strcpy(s, str); } operator int() { int num = 0;原创 2021-06-10 16:29:45 · 224 阅读 · 1 评论 -
C++面向对象的编程-练习8(对象数组+数组旋转符号的重载)
1·题目介绍2·我的回答#include<iostream>#define M 3using namespace std;class Array{private: int b[M][M];public: Array(int(*p)[M] = 0) { int i, j; for (i = 0; i < M; i++) { for (j = 0; j < M; j++) { b[i][j] = p[i][j]; } }原创 2021-06-08 20:04:00 · 148 阅读 · 1 评论 -
C++面向对象的编程-练习7(继承+字符数组的定义+指针+虚函数)
1·题目介绍2·我的回答#include<iostream>using namespace std;class Base{protected: char name[8]; int num;public: Base() { cin >> name; } void print() { cout << "姓名为:" << name << endl; cout << "分数为:" << nu原创 2021-06-07 22:48:26 · 111 阅读 · 0 评论 -
C++面向对象的编程-练习6(继承+指针+虚函数)
1·问题2·我的回答#include<iostream>#include<cmath>using namespace std;class RECT{private: double x; double y;public: RECT(double x1, double y1) { x = x1; y = y1; } virtual double area() { return x * y; } double peri() { retu原创 2021-06-07 22:09:34 · 89 阅读 · 0 评论 -
C++面向对象的编程-练习5(person类继承/2019年期中考试)
【题目】1. 设计如下类CPerson实现对人的封装,包括私有数据成员:身份证号ID、姓名Name和年龄Age。定义含三个参数的构造函数、拷贝构造函数;定义函数set(),提示键盘输入ID、Name和Age,以修改身份证号、姓名和年龄;定义输出函数display()。#include<iostream>using namespace std;class CPerson{private: int ID; string Name; int age;public: CPerson(原创 2021-05-16 10:49:19 · 674 阅读 · 2 评论 -
C++面向对象的编程-练习4(学籍继承类)
【题目】编写一个学生1和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩、教师数据有编号、姓名、职称和部门。要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师数据操作类teacher的基类#include<iostream>using namespace std;class Person{private: int ID; string Name;public: Person(int i = 0, string na = " ")原创 2021-05-16 10:46:18 · 211 阅读 · 0 评论 -
C++面向对象的编程-练习3(学生成绩设置与输出,静态数据成员的运用)
声明一个Student类,在该类中包括一个数据成员:score(代表课程成绩)、两个静态数据成员:total_score(代表总分),count(代表学生总人数)。成员函数有:构造函数、析构函数、account(int)用于设置分数、静态成员函数sum()返回所有学生的总成绩、静态成员函数average()返回所有学生的平均成绩、print()用于打印当前学生对象的成绩等。在主程序中,输入某班同学的成绩,并调用上述函数打印全班同学的成绩、求出全班学生的成绩之和与平均分等。·#include<ios原创 2021-04-22 19:56:59 · 3111 阅读 · 0 评论 -
C++面向对象的编程-练习2(--与==的重载)
在复数类Complex内部实现运算符–和==#include<iostream>using namespace std;class Complex{ int x,y;public: Complex(int x1=0,int y1=0) { x=x1; y=y1; } Complex operator--(int)//后缀-- { x--; y--; return Complex(x+1,y+1); } Complex operator--()//原创 2021-04-19 20:57:25 · 86 阅读 · 0 评论 -
C++面向对象的编程-练习1(location类的友元函数)
题目如下·····设计一个用来表示直角坐标系的Location类,在主程序中创建类Location的两个对象A和B,要求A的坐标在第3象限,B的坐标点在第2象限,分别采用成员函数和友元函数计算给定两个坐标点之间的距离,要求按如下格式输出结果:A(x1, y1), B(x2, y2)Distance1=d1Distance2=d2·解答如下:#include<iostream>#include<cmath>using namespace std;class Lo原创 2021-04-17 09:54:09 · 754 阅读 · 0 评论