Lab 3 function and arguments passing



CSC230 Lab 3

Goal: This lab includes function and arguments passing. You will use pointers, array.
Please try your best to finish the lab in class, and submit it to CANVAS.
PART I: Reverse a given string
In this part, you are provided with a file called charP.cpp. The main function in this file
uses a function called reverse(), which is defined in a different file misc.cpp. The
reverse() function reverses the a given string. For example, if a string “hello” is passed as
argument to reverse(), the string will be changed to “olleh”.
When we run this program, we have:
Please note:
• Do not change anything in charP.cpp
• The reverse() function must be defined in misc.cpp file
• Read page 24 of our Quick C++ Introduction slides. It shows how to work on
multiple files for one project
• Inside reverse() function, you can use *(p+i) to access array element, where p is
the char pointer (which points to the begin of the char array) and i is the index
value of the element
• When you compile, type
g++ charP.cpp misc.cpp
PART II: Read values from command line
Write a file arrD.cpp. This program reads in five char values from keyboard, save them
into an array, array size is 50. The program then reads an index value, then deletes the
value at the given position. In fact, to delete it, the program move all the following values
shifted to left. For example, if we have the following values in the array:
0 1 2 3 4
If the user types index value 2, the values in the array will be:
0 1 2 3 4
In the above example, we list the indices under the char values.
When you run the program, the result should be:
The result is: P I O T
Please note:
1.In the program, the values will be shifted to the left.
2.When the result is printed out, the char values are separated by one space.
Wrap up
When you’re done, jar three files to lab3.jar
jar –cvf lab3.jar *
Submit lab3.jar to Canvas.
Make sure you logout before you leave!
If you cannot finish lab in class, please save all your files. Next time you login the
computer in the lab, you can continue work on your files. Please save them before you
logout. If you work in a Linux lab, please save the file to your machine. However, if you
are working in the Mac lab, please save the file to a CLOUD. The Mac machine will
erase everything you saved once you logout.


There are no reviews yet.

Be the first to review “Lab 3 function and arguments passing”

Your email address will not be published.