how to convert c to c++ code

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;
}
Change main() to int main()
Better than that, why don't you just do your own homework and get yourself an 'A'?
It's already a C++ program. Why do you think you need to change anything?
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
C is (very nearly) a strict subset of C++. Fix your main() and it becomes C++
Here a few links to get you started:
http://www.cplusplus.com/articles/1ywTURfi/
http://www.cplusplus.com/articles/S3wTURfi/
C++ is an object oriented language. Decide what the objects are in your program and make classes to deal with them.

p.s. Learn to use code tags
http://www.cplusplus.com/articles/z13hAqkS/
Do you want to convert it into seperete class and then implement it in the main() function .
You also need iosteam instead of stdlib dont you
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
Im sorry i meant to write stdio. I use stdlib.h for abort() but can i use cstdlib as the proper c++ substitute?
Yes you can :)
ty
thank you very much. all the answer is improve me
Topic archived. No new replies allowed.