const int SIZE = 20;
class Plorg {
private:
char name[SIZE];
int CI;
public:
Plorg(char* na="Plorga",int ci=50);
void resetCI(int ci);
void show();
};
#include "stdafx.h"
#include "plorg.h"
#include<iostream>
using namespace std;
Plorg::Plorg(char* na, int ci) {
strcpy_s(name, na);
CI = ci;
}
void Plorg::resetCI(int ci) {
CI = ci;
}
void Plorg::show() {
cout << "name: " << name << endl;
cout << "CI: " << CI << endl;
}
#include "stdafx.h"
#include "plorg.h"
#include<iostream>
using namespace std;
int main()
{
Plorg p1;
Plorg p2 = Plorg("claire");
cout << "p1:\n";
p1.show();
p2.resetCI(100);
cout << "p2:\n";
p2.show();
return 0;
}
typedef int Item;
class List
{
private:
static const int MAX = 100;
Item items[MAX];
int top;
public:
List() { top = 0; }
bool add(const Item item);
bool isempty() const;
bool isfull() const;
void visit();
};
#include "stdafx.h"
#include "list.h"
#include<iostream>
using namespace std;
bool List::isempty() const
{
return top == 0;
}
bool List::isfull() const
{
return top == MAX;
}
bool List::add(const Item item) {
if (top < MAX) {
items[top++] = item;
return true;
}
return false;
}
void List::visit() {
cout << "\nDisplay the item:\n";
for (int i = 0; i < top; i++)
cout << items[i] << endl;
}
#include "stdafx.h"
#include "list.h"
#include<iostream>
using namespace std;
int main()
{
List l;
if (l.isempty())
cout << "EMPTY!\n";
if (l.isfull())
cout << "ISFULL!\n";
cout << "add 3.\n";
l.add(3);
cout << "add 4.\n";
l.add(4);
if (l.isempty())
cout << "EMPTY!\n";
if (l.isfull())
cout << "ISFULL!\n";
l.visit();
return 0;
}