Programming Solution: Flowcharts, Program Logic and Algorithm Design

Verified

Added on  2023/06/04

|9
|1081
|131
Homework Assignment
AI Summary
This assignment solution covers fundamental programming concepts, including flowcharts, program logic, and algorithm design. It begins with flowchart creation for basic banking operations such as checking accounts, depositing, withdrawing, and transferring funds. The solution then analyzes a C program, examining its output and the effects of code modifications, including removing spacing and altering array sizes. Additionally, it demonstrates the conversion of a 'for' loop into a 'while' loop. The assignment also presents a step-by-step algorithm for managing data input for a series of running races, focusing on data validation, time recording, and calculating average times for specific age groups. Finally, the solution consolidates requirements into a detailed algorithm, outlining the process of data input, validation, and result output.
Document Page
Simple Programming
Name
Institution
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1
1.0 Question One
Flowchart is defined as the program design tool that is used for illustrating the step-by-step
actions taken by the program or the methods. Some of the logical sequences are used for
arranging the steps of the flowchart. Various symbols are used in flowchart for showing
input/output, processing and connectors. Flow lines are used to connect these symbols to each
other. These charts help in solving many of the problems that are faced by the native
programmers (Hooshyar et al. 2015).
Flow chart for:
a. Check account
Figure 1: Flow Chart for checking account
Document Page
2
b. Deposit into account
Figure 2: Flow Chart for depositing into account
c. Withdraw from account
Figure 3: Flow Chart for Withdrawing from account
Document Page
3
d. Transfer to another
Figure 4: Flow Chart for Transferring to another Account
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4
2.0 Question Two
a. Logic of the program
The program will have the following output.
Unix Terminal> cc verify.c
Unix Terminal> ./a.out
Bad weather!
Unix Terminal>
What is presented here is that the program simply copies both the two string obtained
from the s and the s1 as defined above. From the requirement statements, s contains the
word ‘Bad’ while the string s1 has the word ‘weather’. From this case, the two are copied
to the new string named sen. The general working of this program is that all the contents
of string s are copied to the point where you reach the ‘\0’. Immediately this coping is
done, also the contents of s1 are all copied once again to the last point ‘/0’. With this
process all done, the two string are combined together to form the sen string.
b. What happens in removing the ‘sen[i++]=’’;’.
Unix Terminal> cc verify.c
Unix Terminal> ./a.out
Badweather!
When sen[i++]= ' ' is removed, it will simply mean no spacing. Removing this line of
code will result to the removal of the space between the words ‘Bad’ and ‘weather’. The
output above clearly states this words ‘Bad’ and ‘weather’ have been separated
immediately they are copied.
c. Output of replacing sen[i] with the sen[j].
Unix Terminal> cc verify.c
Unix Terminal> ./a.out
weather!
Document Page
5
From the output above, the inner loop shown above starts the loop once again for the sen
hence the contents of s1 will be contained herein as a result of replacing the sen[j] for the
other sen[i].
d. Outcome of replacing the sen[20] with array of size 10
code output after changing sen array size to 10
Unix Terminal> cc verify.c
Unix Terminal> ./a.out
Bad weather!
Changing the array size has nothing to do with the output of the program as shown
above.
e. Rewriting code using control structure
We are given the following code: -
for(j=0;s1[j]!='\0';j++, i++)
sen[i]=s1[j];
The task arises during the code conversion to a while loop which shows the following
case: -
j=0;
while(s1[j]!='\0'){
sen[i]=s1[j];
j++;
i++;
}
Document Page
6
3.0 Question three
Start of algorithm.
This is a step-by-step procedure that helps the programmer to understand all the procedures and
the steps that need to be followed in order to developed a well-organized system (Geldreich et al.
2018).
Step one: Get the input data from the user for the mentioned 3 run races (400m,200m,100m)
Step two: Input data which includes registration number and age of each participant.
Step three: If registration number is correct, go to step five.
Step four: Re-enter the registration number and the time of the participant.
Step five: Get the input for a total of 40 participants.
Step six: capture all the time for every participant
Step seven: Focus on those aged 60 and above and add their times
Step Eight: Calculate their average
Step nine: Exit.
4.0 Question four
Based on Requirement 1:
User should input data for each participant in the correct format.
If the details found to be incorrect, user has to re-enter the data.
Record the time (number of seconds) for each separate event for an individual.
Separate events which include 400m, 200m, 100m for all the 40 participants.
User should indicate when data for last participant has completed.
For better convenience, record all the times as whole numbers (number of seconds)
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7
Based on Requirement 2:
Select the fastest runner of all the participants by noting down their time (number of seconds)
Selected fastest runner should be indicated by his registration number.
Note down the average time needed for a participant who are aged 60 and above based on
requirement 1, by using their registration number mention the fastest runner.
After getting all the inputs and the process done, output the result to the user.
Exit.
From the above given requirement 1 and requirement 2, algorithm comprising of all the
specification has been provided step by step.
Document Page
8
References
Geldreich, Katharina, Mike Talbot, and Peter Hubwieser. 2018. "Off to new shores: preparing
primary school teachers for teaching algorithmics and programming." In Proceedings of
the 13th Workshop in Primary and Secondary Computing Education, p. 26. ACM.
Hooshyar, Danial, Rodina Binti Ahmad, Mohd Hairul Nizam Md Nasir, Shahaboddin
Shamshirband, and Shi-Jinn Horng. 2015. "Flowchart-based programming environments
for improving comprehension and problem-solving skill of novice programmers: a
survey." International Journal of Advanced Intelligence Paradigms 7, no. 1: 24-56.
chevron_up_icon
1 out of 9
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]