Thread: Inventory Program, Need Help

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    3

    Exclamation Inventory Program, Need Help

    Hellow,

    Uhmm, I have a program here that i need help with..
    this is a inventory program.. Using Class, I have a problem on how to display the description of the item.. here is the code:

    Code:
    #include<iostream.h>
    #include<process.h>
    #include<conio.h>
    #include<string.h>
    #include<stdio.h>
    
    class A{
    	private:
    		int a,b;
    		char itemd[30];
    	public:
    		A() {a=b=0;}
    		void SetA(int,int);
    		void setDes(char D[30]){strcpy(itemd,D);}
    		int getA(void) {return a;}
    		int getB(void) {return b;}
    		int Getsum() {return (a+b);}
    		int getDes(void){cout<<itemd;}
    }AA[50];
    void A::SetA(int x, int y){
    	a=x;
    	b=y;
    }
    void DisplayList(int size){
    	cout<<"Index #\t A\tB\t"<<endl;
    	for (int i=0; i<size; i++){
    		cout<<i<<"\t"<<AA[i].getA()<<"\t"<<AA[i].getB()<<"\t"<<AA[i].getDes()<<endl;
    	}
    
    }
    void Add_A(int index){
    	clrscr();
    	int num1,num2;
    	char des[30];
    	cout<<"Enter value for a: "; cin>>num1;
    	cout<<"Enter value for b: "; cin>>num2;
    	cout<<"Enter Des: "; gets(des);
    	AA[index].SetA(num1,num2);
    	AA[index].setDes(des);
    }
    void Edit_A(int index){
    	clrscr();
    	int a,b;
    	cout<<" a = "<<AA[index].getA()<<endl;
    	cout<<" b = "<<AA[index].getB()<<endl<<endl;
    
    	cout<<" Set new values for a and b "<<endl;
    	cout<<" a = "; cin>>a;
    	cout<<" b = "; cin>>b;
    	AA[index].SetA(a,b);
    }
    void Delete_A(int index){
    	AA[index].SetA(0,0);
    }
    int menuList(int size){
    	int option;
    	clrscr();
    	DisplayList(size);
    	cout<<"\n\n1 - ADD		2- EDIT 3 - DELETE	4 - EXIT";
    	cin>>option;
    	return option;
    }
    main(){
    	int counter=0;
    	int ans=menuList(counter);
    	while (ans != 4){
    	switch(ans){
    		case 1: Add_A(counter);
    			counter++;
    			break;
    		case 2: int i;
    			cout<<"Enter index numberto edit (0 -"<<counter-1<<"): "; cin>>i;
    			if (i <=counter)
    				Edit_A(i);
    			break;
    		case 3: int il;
    			cout<<"Enter index number tp delete (0 - "<<counter-1<<"): "; cin>>il;
    			if (il <=counter)
    				Delete_A(il);
    		case 4: exit(0);
    
    		default: cout<<"Try Again..";break;
    
    		}
    
    	ans=menuList(counter);
    
    	}
    
    	return 0;
    
    	}
    Notice the codes which are colored red, that is where I put the code for the display, But the problem is I don't know how to declare the code in public: (Notice the code colored in blue)

    I need help guys.. Please.. Thank you..
    Last edited by pfdandk; 03-24-2010 at 03:38 AM.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    you have declared itemd as being an array of 30, but then in your function definition you just try to cout 'itemd'

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    But then i just need to output what is to be inputted on itemd.. but how do i do that? i just need the syntax..

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I'm not sure what your question is. That appears (at first glance) to be legal code. Does it compile? If not, what are the errors? If it does compile, does it do what you want? If not, what does it do (or not do) that you don't want (or do want)?

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    Okay.. It compiles and it runs.. what i want to achieve is this, I want the User to input the description of the Item, Then I want it the description to be displayed.. I tried to do that but Failed..it wont display.. for display an integer its this code that is needed


    int getA(void) {return a;}

    but what about displaying a character? what is the code for that?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So, what, you want "return itemd;" then?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

Tags for this Thread