C++作业
无
River_Distance
这个作者很懒,什么都没留下…
展开
-
实验20
#include<iostream>using namespace std;class Time;ostream & operator <<(ostream &out,const Time &t3);class Time{public: Time(int t=0,int m=0,int s=0):hour(t),minute(m),second(s) {} friend Time operator +(Time &t2); frie原创 2020-12-21 20:36:28 · 137 阅读 · 1 评论 -
实验19
任务1#include<iostream>using namespace std;class Mammal{public: Mammal() { cout << "Mammal" << endl; } ~Mammal() { cout << "~Mammal" << endl; }};class Dog:public Mammal{public: Dog() { cout << "Dog" << en原创 2020-12-21 18:18:38 · 112 阅读 · 0 评论 -
实验18
任务1#include<iostream>using namespace std;class Object{public: void setweight(double newweight) {weight=newweight;} double showweight() {return weight;} Object(double w):weight(w){cout<<"Object Constr"<<endl;} ~Object(){cout<&l原创 2020-12-11 17:00:20 · 79 阅读 · 0 评论 -
实验17
任务1#include<iostream>using namespace std;void pass1(){ char str[100]; cin.getline(str, 100); cout << str << endl;}任务2#include<iostream>#include<string>using namespace std;void pass2(){ string s1, s2; cin >&原创 2020-12-10 19:43:27 · 70 阅读 · 0 评论 -
实验16 任务4
#include <iostream>using namespace std;class Point {public: Point() : x(0), y(0) { cout << "Default Constructor called." << endl; } Point(int x, int y) : x(x), y(y) { cout << "Constructor called." << endl; } ~Poin原创 2020-12-10 19:15:57 · 202 阅读 · 0 评论 -
实验15
任务一#include<iostream>using namespace std;int main(){ double ted=20.2; double *ptr = &ted; cout << "ted=" << ted << endl; cout << "*ptr=" << *ptr << endl; return 0;}原创 2020-11-27 17:36:21 · 109 阅读 · 0 评论 -
实验14 任务4
#include<iostream>using namespace std;class Point { //类的定义public: //外部接口 int max, min, sum; void get(int NewX, int NewY); int x, y;};void Point::get(int newX, int newY){ x = newX; y = newY;}int main(){ int max, min,sum; Point a[10];原创 2020-11-22 16:58:34 · 107 阅读 · 0 评论 -
矩阵转置
#include<iostream>using namespace std;int another(){ int num[4][4]; int i, j; for (j = 0;j < 4;j++) { for (i = 0;i < 4;i++) { cin >> num[i][j]; } } int anothernum[4][4]; for (i = 0;i < 4;i++) { for (j = 0;j < 4原创 2020-11-22 11:05:05 · 139 阅读 · 0 评论 -
实验14 任务1,2
#include<iostream>#include<cmath>using namespace std;double P1();int P2_1();int P2_2();int P2_3();int P2_4();int main(){ P2_4();}double P1(){ int i; double a; double numble[4]; cout<<"请输入数字:"; for(i=0;i<5;i++) { ci原创 2020-11-21 21:11:30 · 82 阅读 · 0 评论 -
n的自增
main.cpp#include<iostream>using namespace std;void fn1();int n;int main(){ n=100; fn1(); cout<<n<<endl; return 0;}fn1.cpp#include<iostream>#include<cmath>using namespace std;extern int n;void fn1(){ n++;}原创 2020-11-06 17:31:51 · 83 阅读 · 0 评论 -
友元
#include<iostream>using namespace std;class X;class Y{public: int g(X &B);private: static X B;};class X{ friend class Z;public: X(int num=0) { i=num; } friend int h(X &A); friend int Y::g(X &B);private: int i;};cla原创 2020-11-06 16:53:58 · 84 阅读 · 0 评论 -
车船总重
#include<iostream>using namespace std;class Car;class Boat{ friend class Car;public: friend int getTotalWeight(Boat &weight1,Car &weight2); Boat(int B_weight) { weight1=B_weight; } Boat(Boat& boat1) { weight1=boat1.weight1原创 2020-11-06 16:36:23 · 90 阅读 · 0 评论 -
猫的数量
#include<iostream>#include<string>using namespace std;class Cat{public: Cat(char name[]) { strcpy(C_name,name); numOfCats++; } Cat(Cat& n) { strcpy(C_name,n.C_name); numOfCats++; } string getNameOfcats() { return C_na原创 2020-11-05 19:52:34 · 231 阅读 · 0 评论 -
糖块数据
#include<iostream>#include<iomanip>#include<string>using namespace std;struct CandyBar{ char c_logo[100];//品牌 double c_weight;//重量 int c_calorie;//卡路里};int main(){ CandyBar snack={"MochaMunch",2.3,350}; cout<<"snack's l原创 2020-10-31 12:22:34 · 82 阅读 · 0 评论 -
银行账户系统
#include#includeusing namespace std;class Account{private:char m_name[10];char m_zh[20];double m_money;public:Account(char name[],char zh[],double money);void show();void add(double money);void get(double money);};Account::Account(char name[原创 2020-10-30 19:24:59 · 122 阅读 · 0 评论 -
圆的面积
#includeusing namespace std;class Circle{private:double radius;public:Circle(int r);double getArea();};Circle::Circle(int r){radius=r;}double Circle::getArea(){return radiusradius3.1415926;}int main(){Circle cr(2);cout<<“S=”<&原创 2020-10-30 19:12:28 · 74 阅读 · 0 评论 -
矩形类
#includeusing namespace std;class Rectangle{private:int left_x,left_y;int right_x,right_y;public:Rectangle(int x_1,int y_1,int x_2,int y_2);int Rectangle_S();void output();void outputCenter();};Rectangle::Rectangle(int x_1,int y_1,int x_2,int原创 2020-10-30 18:49:57 · 306 阅读 · 0 评论 -
股票系统
#include#includeusing namespace std;class Stock{private:char S_name[100];int S_num;double S_price;double S_total_value;public://void acquire(char name[],int num,double price);void buy(int num,double price);void sell(int num,double price);void原创 2020-10-30 18:48:25 · 210 阅读 · 0 评论