Great Deal! Get Instant \$10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

1 CSCE 1030 Lab 8 General Guidelines: (for ALL of your programming assignments and labs)  Use meaningful variable names.  Use appropriate indentation.  Use comments, especially for the header,...

1
CSCE 1030 Lab 8

General Guidelines: (for ALL of your programming assignments and labs)
 Use meaningful variable names.
 Use appropriate indentation.
make sure that your submitted code has comments as points may be deducted for
* Author: Jane Doe ( XXXXXXXXXX)
Date:
Instructor:
Description: A small description in your own words
XXXXXXXXXXthat describe what the program does. Any
XXXXXXXXXXadditional flags needed to allow the
XXXXXXXXXXprogram to compile should also be placed
XXXXXXXXXXhere.
*/
* Function: Deposit
Parameters: a double representing account balance and
a double representing the deposit amount
Return: a double representing account balance
after the deposit
Description: This function computes the account
balance after a deposit.
*
A. Swapping and Sorting
This Problem has two parts—Part I and Part II.
Part I: Pass by Reference and Swapping
You do not need to submit the code for Part I.
Type the following code and run it to understand what it does.
mailto: XXXXXXXXXX
2
Now, move the code that swaps the variables to a user-defined function of void return
type to swap them there. Do not move the two cout statements. Make sure your program
can actually swap the values. Check if you need to pass by reference.
Part II: Sorting
Now, you will use the swap function you have written in Part I to sort an a
ay in both
ascending and descending orders.
You need to submit the code for Part II.
Consider the following starter code.
3
Complete the code as follows:
 Write a function that swaps the value of two integers. Use your code from Part I
for this purpose.
 Write a function to sort your a
ay. This function has void return type and takes
three parameters—an a
ay that you need to sort, an integer for the size of the
a
ay and a Boolean variable with a default value.
o When this function is called without any passed value for the Boolean
variable, the default value will be used, and the function needs to sort the
a
ay in the ascending order.
o When this function is called with a value for the Boolean variable as true,
and the function needs to sort the a
ay in the ascending order.
o When this function is called without a value for the Boolean variable as
false, and the function needs to sort the a
ay in the descending order.
o Note that this function must call your swap function.
 Complete the geta
ay function to get the actual size of the a
ay from the
user, and then get the elements of the a
ay using a loop of your choice.
 Complete the function showa
ay to display the contents of the a
ay using a
 Insert appropriate function calls in the main function to display the a
ay in the
co
ect order.
Complete the requested changes, and then save the file as Lab8A.cpp, making sure it
compiles and works as expected. Note that you will submit this file to Canvas.
4
B. Multiple Files
Start with the provided code and understand what it is doing. Suppose we have a class
with 3 students and 5 quiz grades. In the above program, we create a two-dimensional
a
ay with 3 rows (one for each student) and 5 columns (one column for each quiz grade).
Type up this program as Lab8B.cpp and verify its functionality.

Now, make the following changes to your code.
5
 The function computeMaximum computes the maximum quiz score out of the 5
scores of each student and stores them in the maximum a
ay. Write this function
in a C++ code file named computeMaximum.cpp.
 The function showA
ay displays the content of a one-dimensional a
ay
passed to the function. Write this function in a C++ code file named
showA
ay.cpp.
 Create a header file called Lab8_Header.h. Move the include and the using
namespace statements, as well as function and constant declarations to this file.
 Make sure all files are in the same folder before you compile and test.
Complete the requested changes, and then save the file as Lab8B.cpp, making sure it
compiles and works as expected. Note that you will submit this file to Canvas.
C. File I/O
Input data read from the keyboard and output data written to the screen are
temporary and will be lost when the program ends. In this lab component, you will
learn to read/write from /to a file. The reading from/writing to a file in a program is
usually refe
ed to as file I/O (Input/Output). You will use constructs called streams
to read from or write data to a file. Streams are among the first examples of objects
introduced in this course. An object is a special kind of variable. C++ is an Object
Oriented Programming (OOP) language, i.e., it has the ability to handle objects.
Before we get started writing the program, create a text file called Data8C.txt that
will contain the following integer values, each on a separate line as follows:
236
19
2
917
83
148
7
385
74
Working with files consists of the following four steps:
a. Declare the stream variables (don't forget to include li
ary).
. Open the file.
c. Process the file (includes reading from and/or writing to the file).
d. Close the file.
6
You will then write a complete C++ program called Lab8C.cpp that will read from this
file, compute the sum of these integers in the file (reading from the file), and then
write the sum of these integers to another file named “Results8C.txt”.
This means that (after setting up the proper variables and include directives), you
will open the file for reading (what data type will you use for this stream variable?).
As for processing the file, since you know in advance how many integers you will be
eading in, you can use a for loop to read all of the integer values and keep track of
the sum. You do not need to store the numbers, so DO NOT use an a
ay. Use a
single integer variable to read in the values.
Remember, that instead of using cin, you will use your stream variable that you
declared and used to open your files.
Outside of the loop, you will then open Results8C.txt file and write the sum
• Remember to close both files.
• Remember to check if there are issues while opening either file. If there issues,
inform the user and terminate the program.
Complete the requested changes, and then save the file as Lab8C.cpp, making sure it
compiles and works as expected. Note that you will submit this file to Canvas.
You should submit the following files:
 Lab8A.cpp
 Lab8B.cpp
 computeMaximum.cpp
 showA
ay.cpp
 Data8C.txt
 Lab8C.cpp
 Results8C.txt
Now that you've finished the lab, use any additional time to practice writing simple
programs out of the textbook, lectures, or even ones you come up with on your own to
gain some more experience.
Answered Same Day Jul 07, 2021

Solution

Arun Shankar answered on Jul 07 2021
Lab 8C files/Data8C.txt
236
19
2
917
83
148
7
385
74
Lab 8C files/Lab8C.cpp
Lab 8C...
SOLUTION.PDF