Nov 27, 2011 at 1:17am Nov 27, 2011 at 1:17am UTC
i having a problem to convert this c coding to c++ coding...can anyone help me to convert it...i need to use it this tuesday..
#include <stdio.h>
#include<stdlib.h>
void update ();
char name[10][50];
int barcode[50],quantity[50];
float price[50];
int searchkey(int b[100],int key);
int i=0, z=0;
main()
{
int option;
int bar;
int v;
char addnumber;
do {
system ("cls");
printf("\n\t\t+-------------------------------------------------+");
printf("\n\t\t| (SHOP INVENTORY RECORD) |");
printf("\n\t\t+-------------------------------------------------+");
printf("\n\t\t ____________________________________");
printf("\n\t\t | NUMBER | MENU |");
printf("\n\t\t |_________|__________________________|");
printf("\n\t\t | 1 | Display product record |");
printf("\n\t\t | 2 | Update product record |");
printf("\n\t\t | 3 | View product record |");
printf("\n\t\t | 4 | Exit program |");
printf("\n\t\t |_________|__________________________|");
printf("\n\n Please choose a number : ");
scanf("%d",&option);
switch(option){
case 1 :
system("cls");
printf(" ______________________________________________________________________");
printf("\n| BARCODE | NAME | QUANTITY | PRICE (RM) |");
printf("\n|________________|________________________|_____________|______________|\n");
i=0;
while(i<10)
{
printf("|\t%d\t |%12s\t\t |%6d\t|%6.2f\t |\n",barcode[i],name[i],quantity[i],price[i]);
i++;
}
break;
case 2 :
system ("cls");
update();
system ("cls");
break;
case 3 :
system ("cls");
printf("Enter the product's barcode: ");
scanf("%d",&bar);
v=searchkey(barcode,bar);
if(v!=-1)
{
printf("Barcode number=%d\n",barcode[v]);
printf("Product's name=%s\n",name[v]);
printf("Quantity=%d\n",quantity[v]);
printf("Price=RM%f\n",price[v]);
}
else
{
printf("SORRY, THE PRODUCT IS NOT IN OUR LIST\n");
}
break;
case 4 :
{
printf("\n\n\t\t*************************************\n");
printf("\t\t********[ EXIT from SYSTEM ]*********\n");
printf("\t\t*************************************\n\n\n");
return -1;
}
break;
}
printf("Would you like to continue with other task? :\n");
printf("choose [y] for YES or\n");
printf("choose [n] for NO :\t");
scanf("%s", &addnumber);
}
while (addnumber == 'y');
printf("\n\n\t========-------------[ THE END ]---------------========\n\n");
}
void update ()
{
int choice;
do{
printf("enter product's name: ");
scanf("%s",&name[z]);
printf("\nenter product's barcode: ");
scanf("%d",&barcode[z]);
printf("\nenter product's price:RM ");
scanf("%f",&price[z]);
printf("\nenter product's quantity: ");
scanf("%d",&quantity[z]);
printf("______________________________________________________________________");
printf("\nDo you want to add another thing?\n");
printf("\n(1) YES\t\t(2) NO\n\n");
printf("you choose :");
scanf("%d",&choice);
printf("______________________________________________________________________\n\n");
z++;
}
while(choice==1);
}
int searchkey(int b[100],int key)
{
int n;
for(n=0;n<100;n++)
{
if(b[n]==key)
{
return n;
}
}
return -1;
}
Nov 27, 2011 at 1:44am Nov 27, 2011 at 1:44am UTC
Change main()
to int main()
Nov 27, 2011 at 1:48am Nov 27, 2011 at 1:48am UTC
Better than that, why don't you just do your own homework and get yourself an 'A'?
Nov 27, 2011 at 1:49am Nov 27, 2011 at 1:49am UTC
It's already a C++ program. Why do you think you need to change anything?
Nov 27, 2011 at 1:57am Nov 27, 2011 at 1:57am UTC
this is not my homework...... this is my miniproject in c ...so i want to convert it to c++.....im beginner,i want someone to teach me hot to convert it to c++..that why i post this
Nov 27, 2011 at 2:23am Nov 27, 2011 at 2:23am UTC
C is (very nearly) a strict subset of C++. Fix your main() and it becomes C++
Nov 27, 2011 at 3:24pm Nov 27, 2011 at 3:24pm UTC
Do you want to convert it into seperete class and then implement it in the main() function .
Nov 27, 2011 at 11:13pm Nov 27, 2011 at 11:13pm UTC
You also need iosteam instead of stdlib dont you
Nov 27, 2011 at 11:20pm Nov 27, 2011 at 11:20pm UTC
You also need iosteam instead of stdlib dont you
That would be better C++ style, but stdlib is still C++ (as indeed is cstdlib).
Last edited on Nov 27, 2011 at 11:20pm Nov 27, 2011 at 11:20pm UTC
Nov 27, 2011 at 11:24pm Nov 27, 2011 at 11:24pm UTC
Im sorry i meant to write stdio. I use stdlib.h for abort() but can i use cstdlib as the proper c++ substitute?
Nov 28, 2011 at 4:00am Nov 28, 2011 at 4:00am UTC
thank you very much. all the answer is improve me