每个月总有那么一天
garve吧
全部回复
仅看楼主
level 5
苐①只猫 楼主
每个月的28号,garve会神奇的在天空(或床上)的某个角落出现。。。orzzzzzzzzzzzzzzzzzzzz
2006年08月10日 03点08分 1
level 1
为什么是 天空或床上 ?
2006年08月12日 11点08分 2
level 0
// Example code: StreetSnack.cpp
// Code By: Jason Holdsworth Feb09
// The program allows the user to load and save information
// about the meals offered by snack carts in various locations
// student TODO:
// 1. Convert the appropriate data and code into two classes:
// SnackCart and Meal
// 2. A SnackCart stores the owner's name, the cart location, and
// one or more meals Note: not all of the functionality should
// become a part of SnackCart or Meal
// 4. The data should be stored in a single text file, instead of two
// text files
// 5. SnackCarts can be added, removal not required
// 6. Meal ratings and costs can be changed
// 7. Add functionality to find the cheapest meal for each SnackCart
// 8. Add functionality to find the best meal for each SnackCart (of 
// the highest rated meals, choose one with minimal cost)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#include "SnackCart.h"
const int MAX_SIZE = 5; // set small for testing purposes
int loadLocations(string filename, SnackCart locations[], Meal meals[]);
int loadMeals(string filename, Meal meals[]);
void saveLocations(string filename, SnackCart locations[],int count);
void saveMeals(string filename, Meal meals[], int count);
void displayLocations(SnackCart locations[], int count);
void displayBestMeals(SnackCart locations[], int count);
int getMenuOption(void);
void addLocation(SnackCart locations[], Meal meals[], int &locationcount, int &mealcount);
int main(void) {
// snack cart database information
SnackCart locations[MAX_SIZE]; 
Meal meals[MAX_SIZE*MAX_MEAL]; // meals offered at each snack cart
int locationCount = 0;
int mealCount = 0;
bool running = true;
// main program loop
while (running) {
int option = getMenuOption();

2009年05月02日 17点05分 3
level 0
switch (option) {
case 1: 
mealCount = loadMeals("meals.txt", meals);
locationCount = loadLocations("locations.txt", locations, meals);
break;
case 2:
 saveLocations("locations.txt", locations, locationCount);
 saveMeals("meals.txt", meals, mealCount);
break;
case 3:
displayLocations(locations, locationCount);
break;
case 4:
displayBestMeals(locations, locationCount);
break;
case 5:
 addLocation(locations, meals, locationCount, mealCount);
break;
case 6:
running = false;
break;
}
}
return EXIT_SUCCESS;
}
// display the menu commands, and allow user to choose one
int getMenuOption(void) {
cout << endl;
cout << "Menu:" << endl
<< "1 - load snack cart information" << endl
<< "2 - save snack cart information" << endl
<< "3 - display snack cart information" << endl
<< "4 - display cheapest and best meal" << endl
<< "5 - add new snack cart" << endl
<< "6 - exit program" << endl;
cout << "Enter option (1-6): ";
int value;
cin >> value;
return value;
}
// load data for snackcarts, data consists of two files
// locations.txt: a list of locations for each snack cart
// meals.txt: the meal of the corresponding snack cart location
// note: this version only allows one meal per location
int loadLocations(string filename, SnackCart locations[], Meal meals[]) {
int count = 0;
string vlocation;
string vowner;
string dummy;
int vcount;
ifstream dataFile(filename.c_str());
for (count = 0; count < MAX_SIZE; ++count) {
getline(dataFile, vlocation);
if (vlocation.size() <= 0) {
break;
}
getline(dataFile, vowner);
dataFile >> vcount;
getline(dataFile, dummy);
locations[count].set(vowner, vlocation, vcount, meals);

2009年05月02日 17点05分 4
level 0
meals += vcount;
}
dataFile.close();
return count;
}
int loadMeals(string filename, Meal meals[]) {
int count = 0;
string vname, dummy;
float vcost;
float vrate;
ifstream dataFile(filename.c_str());
for (count = 0; count < MAX_SIZE * MAX_MEAL; ++count) {
getline(dataFile, vname);
if (vname.size() <= 0) {
break;
}
dataFile >> vcost;
getline(dataFile, dummy);
dataFile >> vrate;
getline(dataFile, dummy);
meals[count].set(vname, vcost, vrate);
}
dataFile.close();
return count;
}
// save the current data from the locations array and meals array
void saveLocations(string filename, SnackCart locations[], const int count) {
ofstream fileclean(filename.c_str());
fileclean.close();
 for (int i = 0; i < count; ++i) {
locations[i].save(filename);
}
}
void saveMeals(string filename, Meal meals[], const int count) {
ofstream fileclean(filename.c_str());
fileclean.close();
 for (int i = 0; i < count; ++i) {
meals[i].save(filename);
}
}
// display all of the locations and meals currently loaded
void displayLocations(SnackCart locations[], const int count) {
for (int i = 0; i < count; ++i) {
locations[i].display();
}
}
void displayBestMeals(SnackCart locations[], const int count) {
for (int i = 0; i < count; ++i) {
cout << "For the snack cart No." << i+1 <<", ";
locations[i].displaybest();
cout << endl;
}
}
// add a location and a meal
void addLocation(SnackCart locations[], Meal meals[], int &locationcount, int &mealcount) {
 string vlocation;
string vowner;
string vname;
int vcount;
float vcost;
float vrate;
cout << "Enter new location: ";
cin.sync();
 getline(cin, vlocation, '\n');
if(vlocation.length() == 0)
{
cout << "Location input error!" << endl;
return ;
}
 cout << "Enter the owner: ";

2009年05月02日 17点05分 5
level 0
cin.sync();
getline(cin, vowner, '\n');
if(vowner.length() == 0)
{
cout << "Owner input error!" << endl;
return ;
}
cout << "Enter the meal count: ";
cin >> vcount;
if(vcount < 1 || vcount > 5)
{
cout << "The meal count should be 1 ~ 5 !" << endl;
return ;
}
for (int i = 0; i < vcount; ++i) {
cout << "Enter meal " << i+1 << " for Snack Cart No." << locationcount << ": ";
cin.sync();
getline(cin, vname, '\n');
if(vname.length() == 0)
{
cout << "Meal name input error!" << endl;
return ;
}
cout << "Enter meal " << i+1 << " cost: ";
cin >> vcost;
if(vcost <= 0.0)
{
cout << "The meal cost should be positive !" << endl;
return ;
}
cout << "Enter meal " << i+1 << " rate: ";
cin >> vrate;
if(vrate <= 0.0)
{
cout << "The meal rate should be positive !" << endl;
return ;
}
meals[mealcount].set(vname, vcost, vrate);
mealcount ++;
}
locations[locationcount].set(vowner, vlocation, vcount, meals);
locationcount ++;
}
2009年05月02日 17点05分 6
1