Vous êtes sur la page 1sur 2

October 01, 2019

Lab 2
BSSEF18 Afternoon
Total Points: (7*5 + 10 = 45)

 Understanding of global and member functions


 Practicing to make calls on local functions.

Assume that you have the following definition of a struct.


struct partsType
{
string partName;
int partNum;
double price;
int quantitiesInStock;
};

Declare an array, inventory, of 100 components of type partsType.

(NOTE: Each of the following task should be done in a function. Your main program can only have variable
declarations and function calls)

a. Write a C++ code to initialize each component of inventory as follows: partName to null string, partNum
to -1, price to 0.0, and quantitiesInStock to 0. (Determine if function is global or a member function)

b. Write the definition of a void function that can be used to input data in a variable of type partsType.
Also write a C++ code that uses your function to input data in inventory. (hint: for this part you need two
functions. First one is local member function to take input in a variable of type partsType. Second is global
function that prints all objects in inventory by calling first function of each object )

c. Write the definition of a void function that can be used to output data of a variable of type partsType.
Write a C++ code that uses a loop to output the data stored in inventory. Assume that the variable
length indicates the number of elements in inventory. (Determine if functions are global or a member
function)

d. Write a C++ code that prints only one item’s information stored in inventory at a given index. Also check
if given index is within range of inventory size or number of items in inventory. The variable length indicates
the number of elements in inventory . (Determine if function is global or a member function)

e. Write a C++ code that prints all the items in inventory with price lower than a given amount. (Determine
if function is global or a member function)

f. Write a C++ code that prints all the items in inventory with price higher than a given amount. (Determine
if function is global or a member function)

g. Write a C++ code that prints all the items in inventory with price between given lowerAmount and
upperAmount. You must use the two functions from part ‘e’ and part ‘f’. (Determine if function is global
or a member function)

Test all your functions by simply calling them in main and get them evaluated.
Write a main program with menu that allows user to do following tasks in an infinite loop.

1. Enter new inventory item. // it will get all necessary inputs from user
2. Print inventory item at any location. //it will get location of item in inventory from user
3. Print inventory items with price below a certain amount. // it will get amount as input from user
4. Print inventory items with price above a certain amount. // it will get amount as input from user
5. Print inventory items with price between two amounts. // it will get amounts as input from user

Vous aimerez peut-être aussi