p6p
3/29/2016 - 10:51 AM

12.c

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

class HotDogStand {
public:
	int id, n;
	static int total;
	
	HotDogStand(int _id) {
		id = _id;
		n = 0;
	}
	
	void JustSold() {
		++n;
		++total;
	}
};

int HotDogStand::total = 0;

int main(int argc, char *argv[]) {
	srand(time(NULL));
	HotDogStand h[] = {
		HotDogStand(1),
		HotDogStand(2),
		HotDogStand(3),
		HotDogStand(4),
		HotDogStand(5),
	};
	
	for (int i=0; i<5; ++i) {
		for (int j=0; j<rand()%8+3; ++j) {
			h[i].JustSold();
			cout << "id " << i << " sold" << endl;
		}
		cout << endl;
	}
	cout << endl;

	for (int i=0; i<5; ++i) {
		cout << "id" << i << ": "<< h[i].n << endl;
	}	
	cout << "Total: " << HotDogStand::total;
	
}
#include <iostream>
#include <string>

using namespace std;

class Month {
	int m;
	string name[7];
	
	void initName() {
		name[0] = "JAN";
		name[1] = "FEB";
		name[2] = "MAR";
		name[3] = "APR";
		name[4] = "MAY";
		name[5] = "JUN";
		name[6] = "JUL";
		name[7] = "AUG";
		name[8] = "SEP";
		name[9] = "OCT";
		name[10] = "NOV";
		name[11] = "DEC";
	}

public:
	void setMonth(string _name) {
		for (int i=0; i<12; ++i) {
			if (_name == name[i]) {
				m = i + i;
				return;
			}
		}
	}
	
	void setMonth(int _m) {
		m = _m;
	}
	
	Month(int _m) {
		initName();
		setMonth(_m);
	}
	
	Month(string _name) {
		setMonth(_name);
	}
	
	string getName() {
		return name[m-1];
	}
	
	int getInt() {
		return m;
	}
};
int main(int argc, char *argv[]) {
}