0% found this document useful (0 votes)
23 views2 pages

Workshop 02

The document provides instructions on creating a C++ struct called Product to store product information like code, name, and price. It defines functions like accept() to take in product details from user input, display() to output product information, and set() to assign values to a product. An example main() function demonstrates creating Product objects, calling the functions, and displaying the results.

Uploaded by

Duc Filan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Workshop 02

The document provides instructions on creating a C++ struct called Product to store product information like code, name, and price. It defines functions like accept() to take in product details from user input, display() to output product information, and set() to assign values to a product. An example main() function demonstrates creating Product objects, calling the functions, and displaying the results.

Uploaded by

Duc Filan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

to design a C++ struct that includes some behavior and

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$

You might also like