This document contains instructions for three lab exercises in C++ functions:
1. Write a function that takes a struct containing a shoe style and price as input, and returns a struct of the same type with the price reduced by 10%.
2. Write a program that passes an array of 5 student ages to a function, which calculates the average age and displays it in the main function.
3. Create a program with three functions to calculate the mean, range, and sort an initialized array of 10 integers. The program should display a menu to select which function to run and continue/stop running.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
62 views1 page
DSA Lab Exercise 2
This document contains instructions for three lab exercises in C++ functions:
1. Write a function that takes a struct containing a shoe style and price as input, and returns a struct of the same type with the price reduced by 10%.
2. Write a program that passes an array of 5 student ages to a function, which calculates the average age and displays it in the main function.
3. Create a program with three functions to calculate the mean, range, and sort an initialized array of 10 integers. The program should display a menu to select which function to run and continue/stop running.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
Lab exercise 2: Functions (C++ revision)
1. ShoeType is a US ER D EF IN ED DA TA T Y PE with the following definition, struct ShoeType
{ char style; double price; }; Write a function definition which corresponds to the following function declaration: ShoeType discount (ShoeType old_record); This discount function returns a structure that is the same as its argument, But with the price reduced by 10%. 2. Write a C++ program to pass an array containing the age of five students to a function. This function should find average age and display the average age in main () function. 3. Create a program which sorts and computes the mean and range, of an array of values. (N.B. first create an array of 10 integers and initialize). Write the program using three functions mean(), range(), sort() At run time your program should display the following menu: = = = = = = = = = Menu = = = = = = = = = = = = = =select a number of your choice (1-3) == = == = = = = 1. Calculate Mean= = = = = = = == = = = = 2. Calculate Range = = = = = = = == = = = 3. Display a sorted array (in ascending order) = = = = = Then once the user inputs a number, the program should compute the results accordingly. Finally the program should ask the user if he/she would like to continue. If the user answers with ‘no’, the program shall stop. Or if the user answers with ‘yes’, the menu above is to be presented again