Commit 771b901e by 李楚霏

10.5-10.8

parent 1585a82a
#include<iostream>
#include"Move.h"
Move::Move(double a, double b) {
x = a;
y = b;
}
Move::~Move() {
std::cout<<"delete"<<std::endl;
}
void Move::showmove() const {
std::cout<<"x: "<<x<<" "<<"y: "<<y<<std::endl;
}
void Move::reset(double a, double b){
x = a;
y = b;
}
Move Move::add(const Move &m) const {
Move n = Move(x + m.x, y +m.y);
return n;
}
\ No newline at end of file
class Move
{
private:
/* data */
double x;
double y;
public:
Move(double a = 0, double b = 0);
~Move();
void showmove() const;
Move add(const Move & m) const;
void reset(double a = 0, double b = 0);
};
class Plorg
{
private:
/* data */
char p_name[19];
int p_CI;
public:
Plorg(const char* name = "Plorga", int CI = 0);
~Plorg();
void ResetCI(int CI =0);
void showPlorg() const;
};
#include"Plorg.h"
#include<iostream>
Plorg::Plorg(const char* name, int CI) {
strcpy(p_name, name);
p_CI = CI;
}
Plorg::~Plorg() {
std::cout<< "delete"<<std::endl;
}
void Plorg::showPlorg() const{
std::cout<<"name: "<<p_name<<"ci: "<<p_CI<<std::endl;
}
void Plorg::ResetCI(int CI) {
p_CI = CI;
}
\ No newline at end of file
#include"list.h"
#include <iostream>
List::List() {
count = 0;
}
bool List::isempty() const
{
return count == 0;
}
bool List::isfull()const {
return count == MAX;
}
int List::itemcount() const {
return count;
}
void List::addItem(const Item & item) {
if(isfull())
std::cout<<"full" << std::endl;
else
items[++count] = item;
}
void List::visit(void (*pf)(Item &)) {
for(int i =0; i < count; ++i)
(*pf)(items[i]);
}
\ No newline at end of file
#ifndef LIST_H
#define LIST_H
#include<string>
const int MAX =10;
struct people {
std::string name;
int age;
};
typedef struct people Item;
class List {
private:
Item items[MAX];
int count;
public:
List();
bool isempty()const;
bool isfull()const;
int itemcount()const;
void addItem(const Item & item);
void visit(void (*pf)(Item &));
};
#endif
\ No newline at end of file
#include<stack>
#include<iostream>
#include"Move.h"
#include"Plorg.h"
#include"list.h"
struct customer {
char fullname[35];
double payment;
};
void addage(Item & item);
int main() {
/*
---- 10.5----
*/
// auto c1 = new customer{"Lee", 10.00};
// auto c2= new customer{"Xu", 11.00};
// double total = 0.00;
// std::stack<customer*> st;
// st.push(c1);
// st.push(c2);
// while(st.size() > 0) {
// customer* tmp = st.top();
// total += tmp->payment;
// st.pop();
// }
// std::cout<<total<<std::endl;
/*
---- 10.6----
*/
// Move m1;
// m1.showmove();
// m1.reset(2,3);
// m1.showmove();
// Move m2 = Move(3,1);
// m2.showmove();
// Move m3;
// m3 = m2.add(m1);
// m3.showmove();
/*
---- 10.7----
*/
// Plorg p1;
// p1.showPlorg();
// p1.ResetCI(2);
// p1.showPlorg();
// Plorg p2 = Plorg("Len", 4);
// p2.showPlorg();
// p2.ResetCI(5);
// p2.showPlorg();
/*
---- 10.8----
*/
List l;
Item i = {"liii", 24};
l.addItem(i);
int n;
n =l.itemcount();
std::cout<<n <<"items in list"<<std::endl;
l.visit(addage);
return 0;
}
void addage(Item & item) {
item.age +=1;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment