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..