InterviewSolution
Saved Bookmarks
| 1. |
Rewrite the following program after removing the syntactical errors (if any). Underline each correction. #include <conio.h>#include <iostream.h>#include <string.h>#include <stdio.h>class product{int product_code, qty, price;char name[20];public:product(){product_code=0; qty=0; price=0; name=NULL;}void entry(){cout<<'\n Enter code, qty, price"';cin>>>product_code>>qty>>price;gets(name);}void tot_price() {return qty*price;} }; void main() { p product;p.entry();cout<<tot_price();} |
|
Answer» #include <conio.h> #include <iostream.h> #include <string.h> #include <stdio.h> class product { int product_code, qty, price; char name[20]; public: product() { product_code=0; qty=0; price=0; strcpy(name, NULL); } void entry() { cout<<'\n Enter code, qty, price"'; cin>>>product_code>>qty>>price; gets(name); } int tot_price() {return qty*price;} }; void main() { p product; p.entry(); cout<<p.tot_price(); } |
|