类
「已注销」
这个作者很懒,什么都没留下…
展开
-
定义Boat与Car两个类,二者都有weight属性,定义二者的一个友元函数getTotalWeight, 计算二者的重量之和
#include <iostream>using namespace std;class car;class boat{ public: boat(int weight) { this->weight = weight; } friend int getTotalWeight(boat &b,car &c); private: int weight.原创 2021-09-15 22:05:44 · 4050 阅读 · 1 评论 -
定义一个Cat类,拥有静态数据成员 numOfCats,记录Cat的个体数目;静态成员函数getNumOfCats(),读取numOfCats。设计程序测试这个类,体会静态数据成员和静态成员函数的用法
#include<iostream>using namespace std;class cat{ public: cat() { numOfCats++; } static int getNumOfCats() { return numOfCats; } ~cat() { numO.原创 2021-09-15 21:59:15 · 7610 阅读 · 2 评论 -
某小型公司,主要有四类人员:经理、技术人员、销售经理和推销员。现在,需要存储这些人员的姓名、编号、级别、当月薪水.计算月薪总额并显示全部信息。
某小型公司,主要有四类人员:经理、技术人员、销售经理和推销员。现在,需要存储这些人员的姓名、编号、级别、当月薪水.计算月薪总额并显示全部信息。人员编号基数为 1000,每输入一个人员信息编号顺序加 1。程序要有对所有人员提升级别的功能。 本例中为简单起见, 所有人员的初始级别均为 1级。然后进行升级,经理升为 4 级,技术人员和销售经理升为 3 级,推销员仍为 1 级。月薪计算办法是: 经理拿固定月薪 8000 元; 技术人员按每小时 100 元领取月薪;推销员的月薪按该推销员当月销售额的 4.原创 2021-09-15 21:57:42 · 2895 阅读 · 1 评论 -
c++类外定义的初步使用
#include<iostream>using namespace std;class demo1{ public : //成员方法:函数 void seta(int A);//函数的类能声明 void setb(int B); void add(); void menus(); void print(); private: //私有属性只能在类能使用 .原创 2021-09-06 20:11:30 · 80 阅读 · 0 评论 -
C++单链表代表头和不带表头用构造函数初步实现
#include<iostream>using namespace std;class list{ public: list(char a) { head = new node(); head->next = NULL; } list(int num) { //head = new node(); .原创 2021-09-07 16:46:05 · 269 阅读 · 0 评论 -
c++用类封装一个mystring,动态数组,构造函数,析构函数,拷贝函数,append()等函数应用
#include<iostream>#include<cstring>using namespace std;class mystring{ public: mystring() { m_p = new char[10]; cout<<"无参构造被调用"<<endl; m_len = 0; } myst.原创 2021-09-08 11:49:14 · 274 阅读 · 0 评论 -
C++使用类实现栈的push和pop
#include<iostream> #define MAX 15enum result_val{EMPTY_OK = 1000,EMPTY_NO = 1001,FULL_OK = 1002,FULL_NO = 1003};using namespace std;class Stack{ public: void initstack(); int full(); void push(int num); int empty(.原创 2021-09-07 13:45:27 · 2096 阅读 · 0 评论