- 博客(11)
- 资源 (4)
- 收藏
- 关注
原创 输入一个非负整数(十进制),输出此整数对应的二进制数
#include <stdio.h>void turn(int n){ if(n==0) { return; } else { turn(n/2); printf("%d",n%2); return; }}int main(){ int num; ...
2018-12-12 15:36:23 6098
原创 小平帮老师处理期末成绩时遇到了问题。他需要计算每个同学的平均成绩,并判断他们是否通过了期末考试不及格成绩(小于60)若都通过才能pass,若没通过要说明是哪几科未通过。因此他需要两个函数,一个求平均成
#include <iostream>#include <string>using namespace std;struct Student{ string number; int Chinese,Math,English;};int avery(Student& s){ return(s.Chinese+s.English+...
2018-12-05 20:41:40 2014
原创 重载流插入运算符 “《”和 流提取运算符“》”,使之能用于该矩阵的输入和输出。 输入 两个2行3列矩阵 输出 矩阵之和
#include <iostream.h>//using namespace std;class Matrix{public: Matrix(); friend Matrix operator+(Matrix &,Matrix &); friend ostream& operator<<(ostream&,...
2018-12-05 20:25:47 3393
原创 定义一个复数类Complex,重载运算符“+”,“-”,“*”,“/”,使之能用于复数的加、减、乘、除。运算符重载函数作为Complex类的成员函数。编写程序,分别求两个复数之和、差、积和商。
#include <iostream>#include <iomanip>using namespace std;class Complex{public: Complex(); Complex(double r,double i); Complex operator+(Complex &c2); Complex ope...
2018-12-05 19:20:18 990
原创 利用抽象基类来完成派生类dog和cat的定义,并利用指向基类的指针实现动态多态,输出不同类型动物的不同叫声。
#include <iostream>using namespace std; class animal //抽象基类---动物类{public: virtual void jiao()=0; //纯虚函数};//将程序需要的其他成份写在下面,只提交begin到end部分的代码//******************** begin *************...
2018-12-05 19:06:08 1319
原创 分别声明Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)类。要求: (1) 在两个基类中都包含姓名、年龄、性别、地址、电话
#include<string>#include <iostream>using namespace std;class Teacher{public: Teacher(string nam,int a,char s,string tit,string ad,string t); void display();protected: s...
2018-12-05 19:00:52 3620
原创 定义了Circle圆形类,在此基础上派生出Cylinder圆柱体类。 Circle圆形类定义如下: class Circle { public: Circle(double r):radius(r
#include <iostream>#include <iomanip>using namespace std;#define PI 3.14class Circle{public: Circle(double r):radius(r){ } double area(){return PI*radius*radius;} //圆面积protecte...
2018-12-05 18:20:08 9112
原创 下面的程序中,存在着两处语法错误。请改正错误,使程序按下面输入输出的规定运行。
#include <iostream>using namespace std;class A{private: int a,b;public: A(int aa, int bb) {a=aa; b=bb;} void printA() { cout<<"a: "<<a<<" b: "<
2018-12-05 17:30:57 3900
原创 如下的代码中,定义了Rectangle矩形类,在此基础上定义Bulk立方体派生类,请在(1)-(6)处填上需要的代码,使程序输出指定长、宽、高的立方体的体积。
#include <iostream>using namespace std;class Rectangle //矩形类{private:int length; //矩形的长和宽int width;public:Rectangle();Rectangle(int l,int w); //构造函数,l、w分别代表长和宽int getArea(); //求面积};...
2018-12-05 17:06:09 912
原创 Student类含有私有数据成员:num,name,sex,公有成员函数: 输入函数get_value()和输出函数display()。采用私有继承方式实现类Student1,增加数据成员:age,a
/* C++代码 */#include <iostream>#include <string>using namespace std;class Student{public: void get_value() { cin>>num>>name>>sex; } void display...
2018-12-05 16:37:22 3967
原创 Student类含有私有数据成员:num,name,sex,公有成员函数: 输入函数get_value()和输出函数display()。采用公用继承方式实现类Student1
#include <iostream>using namespace std;class Student{public: void get_value() { cin>>num>>name>>sex; } void display( ) { cout<<"...
2018-12-05 15:27:50 4569 1
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人