T. Andrew Yang Email:
yang@uhcl.edu Web page
: http://sce.uhcl.edu/yang/ Tel.: (281) 283-3835 |
last updated 9/16: Remaining labs posted 8/23/2021: First published |
|||||||||||||||
Note: An important part of problem solving is correct
understanding of the given problem. -
Try to have a good grasp of
the problem before starting the process of finding the solution(s). -
Use any resources, including
the instructor, the TA, your classmates/friends, and online resources to
ensure that you have correctly understood the given problem. -
While trying to figure out
the solution(s), continue to verify your understanding of the problem. -
Read the given instructions
carefully before taking any action; while preparing
your solutions, be sure to follow the given instructions. 1.
Lab 1 Total points= 100 1.1.
Introduce yourself to the class: Visit the class discussion group in
the Blackboard and complete the following tasks: 1.1.1.
(10 pts)
Throughout this class, you shall
regularly visit the discussion board to find recent announcements and
reminders, and to participate at the discussions. Your participation, or the
lack thereof, will affect your grade. To complete this task, find in the Blackboard the
folder called ‘Discussion Board’ and click the forum named
‘Your Self Introduction’. Post a message (by creating a
thread in that forum); use your full name as the subject line. In your
post, briefly introduce yourself, your previous experience with computer
programming, your general interests/hobbies, and one item you most desire to
learn in this class. Note:
Your
self-intro post should be a brand new thread in that forum; do not
send your self intro as a response to any of your classmates’ posted
messages. 1.1.2.
(10 pts)
Read the messages posted by your
classmates. Pick three of them (or more) and respond with a comment
(encouragement, suggestions, sharing of experiences, etc.) to each of them. 1.2. Developing
C Programs 1.2.1. Figure 1 shows a sample C program.
Figure 1.1. A sample C program
Note: The source program as shown in Figure 1.1 may
contain special characters when being saved into a text file. Fix the errors
by replacing/retyping those characters using a text editor. 1.2.2. Suppose that program is saved as a text file named test.c. Figure 1.2 is a screen
snapshot that shows commands used to compile and execute that program, using
the Tiny C Compiler (tcc), and the sample user input and the output produced
by that program. Figure 1.2. Running the sample program
1.2.3. Save the sample program in Figure 1 as a text file
(with test.c as the file name).
Note: Remember where in the file system you have saved it. 1.2.4. Make the following revisions to the sample program.
Be sure to save the revised program (as test2.c). (a)
Print your own
name as the first line of that program’s screen output. (b)
Add appropriate
comments to explain the purpose/functionality of each of the statements
(comments 1 through 9). (c)
Instead of
getting two numbers from the user, the program will ask for three numbers
from the user. (d)
The result will
be (number1 + number2) * number3. 1.2.5. Run the revised program. Note:
You are strongly encouraged to install a C compiler on your own
computer. TCC is an open-source software and free to download; visit http://download.savannah.gnu.org/releases/tinycc/
if you want to download tcc.
Note:
Not being able to install a C compiler on your own computer is NOT a
valid excuse for being late in submitting the lab.
Computers in the PC labs have Visual Studio installed and you may use them to
complete this portion of the lab. Alternatively, you may use an online C
compiler (e.g., https://www.onlinegdb.com/online_c_compiler)
to develop and test your program.
1.2.6. To hand in: 1.2.6.1.
(30 pts) The
revised C source program per instructions above. 1.2.6.2.
(20 pts) An
image file showing the captured screenshot of the result of your running the
program. Hint: Use the Print
Screen function on the keyboard. 1.3.
The Program
Development Process: 1.3.1.
(10 pts) Explain
the role played by the compiler in
the Program Development Process. What is the input and what is the output? 1.3.2.
(10 pts) Explain
the role played by the linker in
the Program Development Process. What is the input and what is the output? 1.3.3.
(10 pts) Explain
why a data type must be declared first in a program before a data variable is
used. Go to the Index
Total points= 100 2.1. A C program is composed of functions, each of which has a
clearly-defined functionality. A function may call other functions to perform
specific tasks. The calling relationship can be illustrated using a calling graph. 2.1.1.
Study and run the following program to understand how it
works and, in particular, how the various functions are related to each
other. Draw a calling graph to clearly show the order of function calls
and the returned value, if applicable. Hint: Number each of the steps.
2.1.2.
Revise the above program by replacing the commented-out
line (//printf("Hello. Welcome!\n My name is ...\n"); ) with a function call greeting( ). That function will print
a simple greeting message followed by introducing your own name. For example,
when the greeting( ) function is
called, it may display the following greeting message on the screen:
Hello. Welcome!
My name is John Doe. (Note:
Use your own name.) 2.1.3.
To hand
in: 2.1.3.1.
(30 pts) The calling graph
from 2.1.1 above. Note: Include
both the function calls (parameters
if applicable) and the returned values
in your calling graphs. Number
each of the steps/messages in the graph. 2.1.3.2.
(50 pts) The
revised C source program per instructions above. 2.1.3.3.
(20 pts) An
image file showing the captured screenshot of the result of your running the program. Hint: Use the Print Screen
function on the keyboard to get the screenshot. Go to the Index Total points= 100 3.1. Write a program that
asks the user to continue a person’s name, say “John Doe”,
by calling a function called getName( ). The
entered name will be sent back to the main( )
function as a reference parameter (that is studentName
in the partially completed program listed below.
Requirements:
Complete the getName( ) function such that the program generates screen
output as shown below. 3.2. To hand in: 3.2.1.1.
(70 pts) The
completed source program per instructions above. 3.2.1.2.
(30 pts) An
image file showing the captured screenshot of your running the program, by
entering your own name as the user input. Hint: Use the Print
Screen function on the keyboard to get the screenshot. Go
to the Index Total points= 100 4.1. The following is a
partially completed program that continues to (a) first display a menu of commands,
and then (b) asks the user to choose 1 to enter a grade or 0 to quit the
input process. Your job is to complete the main( )
function by implementing a for loop.
4.2. To hand in: 4.2.1.1. (30 pts) Write a pseudocode to
show the logic of the main( ) function. 4.2.1.2.
(50 pts) The
revised C source program per instructions above. 4.2.1.3.
(20 pts) An
image file showing the captured screenshot of the result of your running the
program. Hint: Use the Print
Screen function on the keyboard. Go
to the Index Total points= 100 5.1. The following is a
partially completed program that first displays the content of an integer
array, and then displays the smallest value of all numbers in that
array. Your job is to complete the program by adding the definition of the
function arraySmallestNumber( ), which uses a while loop to find the location
(i.e., its index) of the smallest value in that array. For example, the index
of the smallest value in the following array is 1 because -3 happens to be
the smallest among all the elements in that array. Please note that the
function returns the value of the smallest element in that array; in
addition, it returns the index value of the smallest number as the 3rd
parameter.
5.2. To hand in: 5.2.1.1. (30 pts) Draw a flowchart to
show the logic of the arraySmallestElement( ) function. 5.2.1.2.
(50 pts) The
revised C source program per instructions above. 5.2.1.3.
(20 pts) An
image file showing the captured screenshot of the result of your running the
program. Hint: Use the Print
Screen function on the keyboard. Go
to the Index |