添stl加模板Stock
This commit is contained in:
parent
f351b3f02e
commit
d31083805f
@ -7,8 +7,54 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
Worker::~Worker() {}
|
||||
|
||||
return 0;
|
||||
void Worker::Set() {
|
||||
cout << "Enter worker's name: ";
|
||||
getline(cin, fullname);
|
||||
cout << "Enter worker's ID: ";
|
||||
cin >> id;
|
||||
while (cin.get() != '\n')continue;
|
||||
}
|
||||
|
||||
void Worker::Show() const {
|
||||
cout << "Name: " << fullname << "\n";
|
||||
cout << "Employee ID: " << id << "\n";
|
||||
}
|
||||
|
||||
void Waiter::Set() {
|
||||
Worker::Set();
|
||||
cout << "Enter waiter's panache rating: ";
|
||||
cin >> panache;
|
||||
while (cin.get() != '\n') continue;
|
||||
}
|
||||
|
||||
void Waiter::Show() const {
|
||||
cout << "Category: waiter\n";
|
||||
Worker::Show();
|
||||
cout << "Panache rating: " << panache << "\n";
|
||||
}
|
||||
|
||||
char *Singer::pv[] = {
|
||||
(char *) "other", (char *)"alto", (char *) "contralto", (char *)"soprano", (char *) "base", (char *) "baritone", (char *) "tenor"
|
||||
};
|
||||
void Singer::Set() {
|
||||
Worker::Set();
|
||||
cout <<"Enter number for singer's vocal range:\n";
|
||||
int i;
|
||||
for (i = 0; i<Vtypes ; i++) {
|
||||
cout << i<<" : "<<pv[i] <<" ";
|
||||
if (i %4 == 3) cout<<endl;
|
||||
}
|
||||
if (i %4 != 0) cout<<endl;;
|
||||
while (cin >> voice &&(voice < 0|| voice >= Vtypes))
|
||||
cout<<"Please enter a value >= 0 and < "<<Vtypes << endl;
|
||||
while (cin.get() != '\n')
|
||||
continue;
|
||||
}
|
||||
void Singer::Show() const {
|
||||
cout <<"Category: singer\n";
|
||||
Worker::Show();
|
||||
cout <<"Vocal ranger : "<< pv[voice] << endl;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,36 @@ private:
|
||||
std::string fullname;
|
||||
long id;
|
||||
public:
|
||||
Worker() :fullname("no one"),id(0L){}
|
||||
Worker(const std::string & s,long n) : fullname(s),id(n){}
|
||||
//纯抽象析构杉树 =0
|
||||
virtual ~Worker() =0;
|
||||
virtual void Set();
|
||||
virtual void Show() const;
|
||||
};
|
||||
|
||||
class Waiter : public Worker{
|
||||
private:
|
||||
int panache;
|
||||
public:
|
||||
Waiter():Worker(),panache(0){}
|
||||
Waiter(const std::string & s,long n,int p =0) :Worker(s,n),panache(p){}
|
||||
Waiter(const Worker & wk,int p=0) :Worker(wk),panache(p){}
|
||||
void Set();
|
||||
void Show() const;
|
||||
};
|
||||
|
||||
class Singer :public Worker{
|
||||
protected:
|
||||
enum {other,alto,contralto,soprano,bass,baritone,tenor};
|
||||
enum {Vtypes = 7};
|
||||
private:
|
||||
static char *pv[Vtypes];
|
||||
int voice;
|
||||
public:
|
||||
Singer():Worker(),voice(other){}
|
||||
Singer(const std::string & s,long n,int v = other):Worker(s,n),voice(v){}
|
||||
void Set();
|
||||
void Show() const;
|
||||
};
|
||||
#endif //BASE_WORKER0_H
|
||||
|
93
base/reusing/workermi.cpp
Normal file
93
base/reusing/workermi.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
//
|
||||
// Created by nicemoe on 2021/8/30.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "workermi.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
Worker::~Worker() {}
|
||||
|
||||
void Worker::Data() const {
|
||||
cout << "Name: " << fullname << endl;
|
||||
cout << "Employee ID: " << id << endl;
|
||||
}
|
||||
|
||||
void Worker::Get() {
|
||||
getline(cin, fullname);
|
||||
cout << "Enter waiter's ID: ";
|
||||
cin >> id;
|
||||
while (cin.get() != '\n')continue;
|
||||
}
|
||||
|
||||
void Waiter::Set() {
|
||||
cout << "Enter waiter's name: ";
|
||||
Worker::Get();
|
||||
Get();
|
||||
}
|
||||
|
||||
void Waiter::Show() const {
|
||||
cout << "Category: waiter\n";
|
||||
Worker::Data();
|
||||
Data();
|
||||
}
|
||||
void Waiter::Data() const {
|
||||
cout << "Panache rating: " << panache << "\n";
|
||||
}
|
||||
void Waiter::Get() {
|
||||
cout <<"Enter waither's panache rating: ";
|
||||
cin >> panache;
|
||||
while (cin.get() != '\n')continue;
|
||||
}
|
||||
char *Singer::pv[] = {
|
||||
(char *) "other", (char *) "alto", (char *) "contralto", (char *) "soprano", (char *) "base",
|
||||
(char *) "baritone", (char *) "tenor"
|
||||
};
|
||||
|
||||
void Singer::Set() {
|
||||
cout <<"Enter singer's name: ";
|
||||
Worker::Get();
|
||||
Get();
|
||||
}
|
||||
void Singer::Show() const {
|
||||
cout << "Category: singer\n";
|
||||
Worker::Data();
|
||||
Data();
|
||||
}
|
||||
void Singer::Data() const {
|
||||
cout << "Vocal ranger : " << pv[voice] << endl;
|
||||
}
|
||||
void Singer::Get() {
|
||||
cout << "Enter number for singer's vocal range:\n";
|
||||
int i;
|
||||
for (i = 0; i < Vtypes; i++) {
|
||||
cout << i << " : " << pv[i] << " ";
|
||||
if (i % 4 == 3) cout << endl;
|
||||
}
|
||||
if (i % 4 != 0) cout << endl;;
|
||||
cin >> voice;
|
||||
while (cin.get()!= '\n') continue;
|
||||
}
|
||||
|
||||
void SingingWaiter::Data() const {
|
||||
Singer::Data();
|
||||
Waiter::Data();
|
||||
}
|
||||
|
||||
void SingingWaiter::Get() {
|
||||
Waiter::Get();
|
||||
Singer::Get();
|
||||
}
|
||||
void SingingWaiter::Set() {
|
||||
cout<<"Enter singing waither's name: ";
|
||||
Worker::Get();
|
||||
Get();
|
||||
}
|
||||
|
||||
void SingingWaiter::Show() const {
|
||||
cout <<"Category: singing waither\n";
|
||||
Worker::Data();
|
||||
Data();
|
||||
}
|
||||
|
71
base/reusing/workermi.h
Normal file
71
base/reusing/workermi.h
Normal file
@ -0,0 +1,71 @@
|
||||
//
|
||||
// Created by nicemoe on 2021/8/30.
|
||||
//
|
||||
|
||||
#ifndef BASE_WORKERMI_H
|
||||
#define BASE_WORKERMI_H
|
||||
#include <string>
|
||||
/**
|
||||
* 多重集成 MI引入虚基类
|
||||
*/
|
||||
class Worker {
|
||||
private:
|
||||
std::string fullname;
|
||||
long id;
|
||||
protected:
|
||||
virtual void Data() const;
|
||||
virtual void Get();
|
||||
public:
|
||||
Worker() :fullname("no one"),id(0L){}
|
||||
Worker(const std::string & s,long n) : fullname(s),id(n){}
|
||||
//纯抽象析构杉树 =0
|
||||
virtual ~Worker() =0;
|
||||
virtual void Set() = 0;
|
||||
virtual void Show() const = 0;
|
||||
};
|
||||
|
||||
class Waiter : virtual public Worker{
|
||||
private:
|
||||
int panache;
|
||||
protected:
|
||||
void Data() const;
|
||||
void Get();
|
||||
public:
|
||||
Waiter():Worker(),panache(0){}
|
||||
Waiter(const std::string & s,long n,int p =0) :Worker(s,n),panache(p){}
|
||||
Waiter(const Worker & wk,int p=0) :Worker(wk),panache(p){}
|
||||
void Set();
|
||||
void Show() const;
|
||||
};
|
||||
|
||||
class Singer :virtual public Worker{
|
||||
protected:
|
||||
enum {other,alto,contralto,soprano,bass,baritone,tenor};
|
||||
enum {Vtypes = 7};
|
||||
void Data() const;
|
||||
void Get();
|
||||
private:
|
||||
static char *pv[Vtypes];
|
||||
int voice;
|
||||
public:
|
||||
Singer():Worker(),voice(other){}
|
||||
Singer(const std::string & s,long n,int v = other):Worker(s,n),voice(v){}
|
||||
Singer(const Worker & wk,int v = other):Worker(wk),voice(v){}
|
||||
void Set();
|
||||
void Show() const;
|
||||
};
|
||||
class SingingWaiter :public Singer,public Waiter{
|
||||
protected:
|
||||
void Data() const;
|
||||
void Get();
|
||||
public:
|
||||
SingingWaiter(){}
|
||||
SingingWaiter(const std::string & s,long n,int p =0,int v =other):Worker(s,n),Waiter(s,n,p),Singer(s,n,v){}
|
||||
SingingWaiter(const Worker & wk,int p =0,int v =other):Worker(wk),Waiter(wk,p),Singer(wk,v){}
|
||||
SingingWaiter(const Waiter & wt,int v =other):Worker(wt),Waiter(wt),Singer(wt,v){}
|
||||
SingingWaiter(const Singer & wt,int p =0,int v =other):Worker(wt),Waiter(wt,p),Singer(wt){}
|
||||
void Set();
|
||||
void Show() const;
|
||||
};
|
||||
|
||||
#endif //BASE_WORKERMI_H
|
50
base/reusing/workmi.cpp
Normal file
50
base/reusing/workmi.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// Created by nicemoe on 2021/8/30.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "workermi.h"
|
||||
#include <cstring>
|
||||
const int SIZE = 5;
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
Worker * lolas[SIZE];
|
||||
int ct;
|
||||
for (ct = 0; ct < SIZE; ct++) {
|
||||
char choice;
|
||||
cout <<"Enter the employee category:\n"
|
||||
<<"W: waither s: singer "
|
||||
<<"t:singing waither q: quit\n";
|
||||
cin >>choice;
|
||||
while (strchr("wstq",choice) == NULL){
|
||||
cout <<"Please enter a w, s,t,or q: ";
|
||||
cin >>choice;
|
||||
}
|
||||
if (choice == 'q')
|
||||
break;
|
||||
switch (choice) {
|
||||
case 'W':
|
||||
case 'w': lolas[ct] = new Waiter;break;
|
||||
case 'S':
|
||||
case 's':lolas[ct] =new Singer;break;
|
||||
case 'T':
|
||||
case 't': lolas[ct] = new SingingWaiter;break;
|
||||
}
|
||||
cin.get();
|
||||
lolas[ct]->Set();
|
||||
}
|
||||
|
||||
cout <<"\nHere is your staff:\n";
|
||||
int i;
|
||||
for (i = 0; i < ct; ++i) {
|
||||
cout <<endl;
|
||||
lolas[i]->Show();
|
||||
}
|
||||
for (i = 0; i <ct ; i++) {
|
||||
delete lolas[i];
|
||||
}
|
||||
cout <<"Bye.\n";
|
||||
return 0;
|
||||
}
|
26
base/reusing/worktest.cpp
Normal file
26
base/reusing/worktest.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by nicemoe on 2021/8/30.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "worker0.h"
|
||||
const int LIM = 4;
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
Waiter bob("Bob Apple",314L,5);
|
||||
Singer bev("Beverly Hills",522L,3);
|
||||
Waiter w_temp;
|
||||
Singer s_temp;
|
||||
|
||||
Worker * pw[LIM] = {&bob,&bev,&w_temp,&s_temp};
|
||||
int i;
|
||||
for ( i = 0; i < LIM; ++i) {
|
||||
pw[i] -> Set();
|
||||
}
|
||||
for (i = 0; i < LIM ; ++i) {
|
||||
pw[i]->Show();
|
||||
cout <<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
14
base/stl/stacktp.cpp
Normal file
14
base/stl/stacktp.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by nicemoe on 2021/8/30.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "stacktp.h"
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
16
base/stl/stacktp.h
Normal file
16
base/stl/stacktp.h
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// Created by nicemoe on 2021/8/30.
|
||||
//
|
||||
|
||||
#ifndef BASE_STACKTP_H
|
||||
#define BASE_STACKTP_H
|
||||
|
||||
|
||||
|
||||
class stacktp {
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //BASE_STACKTP_H
|
Loading…
Reference in New Issue
Block a user