Workshop 02
Workshop 02
Please do the followings before starting the work: Create the directory with a name like <class>-<name><roll number>-workshop-01, e.g. SE0412-QuangTV00456-workshop01 (1)
C++ Structures
Learning Outcome Upon successful completion of this workshop, you will be able
1. Product struct Design a C++ struct named Product that holds a code, name and price. Include in your design the following functions and complete them: void accept(Product & x): to let user accept products information from standard input o an integer holding code of the product. o a string of no more than twenty (50) characters holding the name of the product. o a floating point value holding the products price. void display(Product & x): to display information of product void set(int co, char na[], double pr, Product & x);to assign value for product x
struct Product { - code // int - name // char name[50] - price // double }; int main(){ Product a, b = {2202,"Harry Porter",93.5}; display(b); accept(a); display(a); Product c; set(3303,"Mr.Bean Novel",50.5,c);
display(c); system("pause"); }
The result of program is shown as follow: Product information: Code : 2202 Name: Harry Porter Price : 93.5$ Enter code : 666 Enter name: Gonna with the wind Enter price : 77.5 Product information: Code : 666 Name: Gonna with the wind Price : 77.5$ Product information: Code : 3303 Name: Mr.Bean Novel Price : 70.5$