摘要:1 //课本习题8-5 2 #include <iostream> 3 #include <string> 4 using namespace std; 5 class Mammal 6 { 7 public: 8 virtual void speak() 9 { 10 cout<<"动物正在说话"
阅读全文
摘要:1 //实验六任务5 2 #include <iostream> 3 #include <string> 4 using namespace std; 5 class Student 6 { 7 public: 8 Student(int ID,string name); 9 void setnam
阅读全文
摘要:1 //实验六任务2 2 //定义猫科动物Animal类,由其派生出猫类(Cat)和豹类(Leopard), 3 //在Animal类中定义虚函数,输出“My name is Animal”,在派生类中 4 //分别重新定义该函数,显示“My name is **”,其中**为各自类名 5 #inc
阅读全文
摘要:1 //实验六任务2 2 #include <iostream> 3 #include <string> 4 using namespace std; 5 class People 6 { 7 public: 8 People(){} 9 ~People(){} 10 void setValue(i
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 //设计一款电子钟类,用于显示时、分、秒 4 //1.含有形参有默认值的默认构造函数; 5 //2.重载 前缀++ 和 后缀—用于调整时间,每次调整均对秒进行调整,若秒满60,则分加1,若分满60则时加1,
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 //利用多态,实现计算器 4 //多态的好处 5 //1、组织结构清晰 6 //2、可读性强 7 //3、对于前期和后期扩展以及维护性高 8 class AbstractCalculator 9 { 10
阅读全文
摘要:1 //实验五任务三 2 #include <iostream> 3 #include<string> 4 #include <cmath> 5 using namespace std; 6 class vector_N 7 { 8 private: 9 int n; 10 int* p; 11 p
阅读全文
摘要:1 //实验五任务二 2 #include <iostream> 3 using namespace std; 4 class vector3D 5 { 6 private: 7 float x,y,z; 8 public: 9 vector3D() 10 { 11 x = 0; 12 y = 0;
阅读全文
摘要:1 //第9讲课件代码 2 #include <iostream> 3 using namespace std; 4 class CPolygon 5 { 6 protected: 7 int width,height; 8 public: 9 void set_values(int a,int b
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 class Clock 4 { 5 public: 6 Clock(int hour = 0,int minute = 0,int second = 0); 7 void showTime()const;
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 double num,profit = 0; 6 cout<<"请输入收入金额:"<<endl; 7 cin>>num; 8 if(num<3500) 9 { 10 cou
阅读全文
摘要:1 //递增运算符的重载 2 #include <iostream> 3 using namespace std; 4 class Myinteger 5 { 6 friend ostream& operator<<(ostream &cout,Myinteger &myint); 7 public
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 //通过成员函数重载+号 4 class Person 5 { 6 public: 7 Person operator+(Person &p) 8 { 9 Person temp; 10 temp.m_A
阅读全文
摘要:1 //1.10数制转换 2 //给定一个M进制的数x,实现对x向任意的一个非M进制的数的转换 3 #include<stdio.h> 4 #define MAXCHAR 101 5 //字符转换为数字 6 int char_to_num(char ch); 7 //数字转换为字符 8 char n
阅读全文
摘要:1 //1.7最佳存款方案 2 //假设银行一年整存零取的月息为0.63%。现在某人手中有一笔钱,他打算在今后的 3 //五年中的每年年底取出1000元,到第五年时正好取完,请算出他存钱时应存入多少 4 #include<iostream> 5 using namespace std; 6 int
阅读全文
摘要:1 //例8.1 2 #include <iostream> 3 using namespace std; 4 class Complex 5 { 6 public: 7 Complex(double r = 0.0,double i = 0.0):real(r),image(i){} 8 Comp
阅读全文
摘要:1 //拷贝构造函数的调用时机 2 #include <iostream> 3 using namespace std; 4 //1.使用一个已经创建完的对象来初始化一个新对象 5 //2.值传递的方式给函数参数传值 6 //3.值方式返回局部对象 7 class Person 8 { 9 publ
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 //设计圆类和点类,判断点和圆的关系 4 class Point 5 { 6 public: 7 void setX(int x) 8 { 9 m_X = x; 10 } 11 int getX() 12
阅读全文
摘要:1 //设计立方体类,求出立方体的面积和体积,分别用全局函数和成员函数判断两个立方体是否相等 2 #include <iostream> 3 using namespace std; 4 //立方体类设计 5 //1、创建立方体类 6 //2、设计属性 7 //3、设计行为 获取立方体面积和体积 8
阅读全文
摘要:1 //编程一百题 2 //1.4抓交通肇事犯 3 #include <iostream> 4 using namespace std; 5 int num = 0; 6 int main() 7 { 8 for(int i=1;i<=9;i++) 9 { 10 for(int j=0;j<=9;j
阅读全文
摘要:1 //c++语言程序设计第二章习题 2 //2-29 3 //在程序中定义一个整型变量,赋以1~100的值,要求用户猜这个数,比较两个数的大小,把结果提示给用户,直到猜对为止。 4 #include <iostream> 5 using namespace std; 6 #include <cti
阅读全文
摘要:1 //c++语言程序设计第二章习题 2 //2-24 3 #include <iostream> 4 using namespace std; 5 int main() 6 { 7 Flag: 8 cout<<"现在正在下雨吗?是(Y)否(N)"<<endl; 9 char c; 10 cin>>
阅读全文
摘要://c++语言程序设计第二章习题 //2-4 #include <iostream> using namespace std; int main() { const double PI = 3.1416; double a; a = PI; cout<<"a的值为:"<<a<<endl; retur
阅读全文
摘要:中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int year,month,da
阅读全文
摘要:#include <iostream>using namespace std;int main(){ int cock,hen,chicken; for(cock = 0;cock<=20;cock++) { for(hen = 0;hen<=33;hen++) { for(chicken = 0;
阅读全文