CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jul 2007
    Posts
    77

    help with three errors(2 unqualified id, and void before token.)

    /Users/Kevin/Documents/Programming/Xcode/C++/Inventoryclass/main.cpp:57: error: expected unqualified-id before 'void'
    /Users/Kevin/Documents/Programming/Xcode/C++/Inventoryclass/main.cpp:67: error: expected unqualified-id before 'void'
    /Users/Kevin/Documents/Programming/Xcode/C++/Inventoryclass/main.cpp:90: error: expected declaration before '}' token

    i know this is kinda long but please look at these three functions:

    the first error is at: Inventory::void init_inv()
    the second is at: Inventory::void menu();
    the last error is at the last curly brace of the menu function.


    Code:
    #include <iostream>
    using namespace std;
    
    const int SIZE = 100;
    class Item {
    	char *item;
    	double cost;
    	double retail;
    	int on_hand;
    	int lead_time;
    	
    	public:
    		Item(char *item, double cost, double retail, int on_hand, int lead_time);
    		Item(const Item &obj);
    		Item();
    		void setItem(char *c){item = c;}
    		void setCost(double *d){cost = *d;}
    		void setRetail(double *d){retail = *d;}
    		void setOnHand(int *hand){on_hand = *hand;}
    		void setLeadTime(int *time){lead_time = *time;}
    		char *getItem(){return item;}
    		double getCost(){return cost;}
    		double getRetail(){return retail;}
    		int getOnHand(){return on_hand;}
    		int getLeadTime(){return lead_time;}
    };
    Item::Item(char *item, double cost, double retail, int on_hand, int lead_time){
    			this->item = item;
    			this->cost = cost;
    			this->retail = retail;
    			this->on_hand = on_hand;
    			this->lead_time = lead_time;
    		}
    Item::Item(){
    	*item = '\0';
    }
    /*Item::Item(char *item, double cost, double retail, int on_hand, int lead_time)
       : item( item ), cost( cost ), retail( retail ), on_hand( on_hand), lead_time( lead_time )
    {
    }*/
    
    Item::Item(const Item &obj )
       : item( obj.item ), cost( obj.cost ), retail( obj.retail ), on_hand( obj.on_hand), lead_time( obj.lead_time )
    {
    }
    
    class Inventory {
    	Item inventory[SIZE];
    	char *name;
    	Inventory(char *name);
    	Inventory(const Inventory &obj);
    	public:
    	void init_inv(), enter(), update(), display(), menu(), input();
    	char *getName(){return name;}
    	
    };
    Inventory::void init_inv(){
    	
    	cout << "Enter name of the inventory: ";
    	cin >> name;
    	
    	Inventory inv1(name);
    	for(int i = 0; i < SIZE; i++){
    		inventory[i].item = '\n';
    	}
    }
    Inventory::void menu(){
    	char choice;
    	for(;;){
    			do{
    				cout << "Choose one:\n\n";
    				cout << "(E)nter\n(D)isplay\n(U)pdate\nQuit\n";
    		
    			}while(!strchr("eduq", tolower(ch));
    			cin >> choice;
    			switch(ch){
    				case 'E': enter();
    				break;
    				case 'U': update();
    				break;
    				case 'D': display();
    				break;
    				case 'Q':return;
    			}
    		
    		}
    	
    	}
    	
    }
    Inventory::Inventory(char *name){
    	this->name = name;
    	Item inventory[SIZE] = inventory;
    	}
    Inventory::Inventory(const Inventory &obj)
    	: name(obj.name), inventory(obj.inventory){
    	}
    Inventory::void input(int i){
    	cout << "Item: ";
    	cin >> inventory[i].item;
    	
    	cout << "Cost: ";
    	cin >> inventory[i].price;
    	
    	cout << "Retail price: "
    	cin >> inventory[i].retail;
    	
    	cout << "Quantity in stock: ";
    	cin >> inventory[i].on_hand;
    	
    	cout << "Lead time before restock(in days): ";
    	cin >> inventory[i].lead_time;
    }
    Inventory::void enter(){
    	Item temp[SIZE+10];
    	int i;
    	for(i = 0; i < SIZE;i++){
    		if(!*inventory[i].item)
    			break;
    	}
    	if(i == size){
    		cout << "List full!\n";
    		return;
    	}
    	input(i);
    }
    Inventory::void update(){
    	char *item_search;
    	cout << "enter item to update:";
    	cin >> *item_search;
    	
    	for(int i = 0; inventory[i].item;i++){
    		if(!strcmp(inventory[i].item, item_search)){
    			input(i);
    			char ch;
    			cout << "Search again? (y/n)";
    			if(choice == 'y' || choice == 'Y')
    				update();
    				else return;
    		}
    		else {
    			char choice;
    			cout << "Item not found. Search again? (y\n): ";
    			cin >> choice;
    			if(choice == 'y' || choice == 'Y')
    				update();
    				else return;
    		}
    	}
    
    }
    Inventory::void display(){
    	int t;
    	cout << "inventory name: ";
    	//sort();
    	for(t = 0; t < SIZE; t++){
    		if(*invntry[t].item){
    			cout << inventory[t].item << '\n';
    			cout << "Cost $" << invntry[t].cost << '\n';
    			cout << "Retail Price $" << invntry[t].retail;
    			cout << "\nOn hand: " << invntry[t].on_hand;
    			cout << "\nResupply time: ";
    			cout << invntry[t].lead_time << " days\n\n";
    		}
    	}
    
    }
    
    int main () {
    	//cout << "Enter a name for an inventory: ";
    	
    	init_inv();
    	
        return 0;
    }
    Last edited by kevinskrazyklub; July 14th, 2007 at 10:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured