1 Replies - 1234 Views - Last Post: 16 October 2009 - 01:54 PM Rate Topic: -----

#1 Blackbass99   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 13-October 09

Linking A Array To A Menu?

Post icon  Posted 15 October 2009 - 08:22 PM

Having Problems Creating An Array To Store These Values, and Once The Arrays Are Created For bType and mType How Would I Associate It With The Menu?

#include "bookType.h"
#include "memberType.h"
#include <iostream>
#include <string>
#include <fstream>

using namespace std;
string ID;
string firstName;
string lastName;
int booksPurchasedRecently;
double amountSpentRecently;
int booksPurchased;
double amountSpent;
string title;
int noOfAuthors;
string authors[];
string publisher;
int year;
string ISBN;
double price;
int quantityInStock;
int quantitySold;
string s;
int start, end;

int main()
{
	char choice; // Menu
	int x; // Item on list
	cout << "To make a selection, input one of the numbers and press enter." << endl;
	cout << "(1) Book/ISBN List" << endl;
	cout << "(2) Book Information" << endl;
	cout << "(3) Member ID/Name List" << endl;
	cout << "(4) Member Information" << endl;
	cout << "(5) Book Purchase" << endl;
	cout << "(9) Exit" << endl;
	cout << ">> ";
  cin >> choice;
  while(choice != '9'){
	switch(choice){
	  case '1': cout << " Book List " << endl;
				break;
	  case '2': cout << " Enter the ISBN for Book Information: " << endl;
				break;
	  case '3': cout << " Member List " << endl;
				break; 
	  case '4': cout << " Enter Member ID Number To Continue " << endl; 
				break;
	  case '5': cout << " Book Purchase! " << endl;
	  case '9': break;

	  default: cout << "Error: Invalid choice" << endl;
	}// End of break
	cout << "To make a selection, input one of the numbers and press enter." << endl;
	cout << "(1) Book/ISBN List" << endl;
	cout << "(2) Book Information" << endl;
	cout << "(3) Member ID/Name List" << endl;
	cout << "(4) Member Information" << endl;
	cout << "(5) Book Purchase" << endl;
	cout << "(9) Exit" << endl;
	cout << ">> ";
		 cin >> choice;
		 } // End of loop
	
	bookType bType;
	bType.setBookInfo(title, noOfAuthors, authors[10], publisher, year, ISBN, price, quantityInStock, quantitySold);{
	   ifstream infile;
	   string fname;
	   cout << "Enter file name: ";
	   cin >> fname;
	   infile.open(fname.c_str());
	   if(!infile) {
	   cerr << "Error: Can't open file." << endl;
	return 1;
}
 else
   {
  for(int i = 0; i < 100; ++i){
	 infile>>title;
	  do {
	start = 0;
	end = s.find(";");
	if(end >= 0) {
	  cout << s.substr(start, end - start) << endl;
	  start = end + 1;
	  s = s.substr(start, s.length() - start);
	  infile>>noOfAuthors;
	}
	else
	  cout << s << endl;
  } while(end >= 0);
	 infile>>authors[noOfAuthors];
	 infile>>publisher;
	 infile>>year;
	 infile>>ISBN;
	 infile>>price;
	 infile>>quantityInStock;
	 infile>>quantitySold;
	 cout << "Title of Book: " << title << endl;
	 cout << "Authors: " << authors[noOfAuthors] << endl;
	 cout << "Publisher: " << publisher << endl;
	 cout << "Year: " << year << endl;
	 cout << "ISBN: " << ISBN << endl;
	 cout << "Price: $ " << price << endl;
	 cout << "Quantity In Stock: " << quantityInStock << endl;
	 cout << "Quantity Sold: " << quantitySold << endl;
	 cout << " " << endl;
   }
}
   infile.close(); 
}
							 
	
	memberType mType;
	mType.setMemberInfo(ID, firstName, lastName, booksPurchasedRecently, amountSpentRecently, booksPurchased, amountSpent);{
	   ifstream infile;
	   string fname;
	   cout << "Enter file name: ";
	   cin >> fname;
	   infile.open(fname.c_str());
	   if(!infile) {
	   cerr << "Error: Can't open file." << endl;
	return 1;
}
 else
   {
  for(int i = 0; i < 4; ++i){
	 infile>>ID;
	 infile>>firstName;
	 infile>>lastName;
	 infile>>booksPurchasedRecently;
	 infile>>amountSpentRecently;
	 infile>>booksPurchased;
	 infile>>amountSpent;
	 cout << "ID: " << ID << endl;
	 cout << "Name: " << firstName << " " << lastName << endl;
	 cout << "Books Purchased Recently: " << booksPurchasedRecently << endl;
	 cout << "Amount Spent Recently: $" << amountSpentRecently << endl;
	 cout << "Books Purchased Total: " << booksPurchased << endl;
	 cout << "Amount Spent: $" << amountSpent << endl;
	 cout << " " << endl;
   }
}
   infile.close(); 
}
  return 0;
}						  



Just want to store all seperate infiles into two arrays member and booklist. would this work?

const int M = 100; // M for members
const int B = 1000; // B for booklist

M = setMemberInfo();
B = setBookInfo();




and how would I link it to the Menu?

Thanks In Advance! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Linking A Array To A Menu?

#2 #define   User is offline

  • Cannot compute!
  • member icon

Reputation: 1868
  • View blog
  • Posts: 6,763
  • Joined: 19-February 09

Re: Linking A Array To A Menu?

Posted 16 October 2009 - 01:54 PM

Creating an array
Assuming Class is bookType,
and B is constant for maximum number of books.

  const int M = 100; // M for members
  const int B = 1000; // B for booklist

  // create an array of bookType
  bookType books[B];

  // set info for first book in array
  books[0].setBookInfo(title, noOfAuthors, authors[10], 
					 publisher, year, ISBN, price, 
					 quantityInStock, quantitySold);



B)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1