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

1 CSC 101 Computer Science 1 – Fall 2021 Student Name: ________________________________________________ School ID: _____________________ Section Number: ______________ Sections: • H004 Test Breakdown...

1 answer below »
1
CSC 101 Computer Science 1 –
Fall 2021
Student Name: ________________________________________________
School ID: _____________________
Section Number: ______________
Sections:
• H004
Test Breakdown
Concept Knowledge 60 %
Program Analysis 25 %
Program Writing 15 %
Last Name:____________________
2
Grade: ________________________________
Concept Knowledge
Match the following definitions and statements to the terms listed on the right. Note that some terms
may be used more than once while others may not be used at all. (3 pts each)
___________ 1.
In this stage of the Waterfall model, the app
is planned, and the software requirements
are mapped out.
A. Logical
B. Release
C. Pre-Test
D. Body
E. Prototype
F. Sentinel Controlled
Loop
G. Plan
H. Local Variable
I. Syntax
J. Pre-defined function
K. Post-Test
L. Return Type
M. Pseudocode
N. Develop
O. Void
P. Condition/Expression
Q. Test
R. Flowchart
S. Paramete
T. Initialization
U. Runtime
V. Design
W. Global Variable
X. Count Controlled
Loop
Y. Step
___________ 2.
This type of e
or occurs when the
operating system/computer cannot execute
a line of code in a program.
___________ 3.
This is the phase of a for loop where the
counting variable in initialized/created.
___________ 4.
This type of design approach involves
creating a high level/informal description of
a program that does not adhere to any
particular programming language’s rules.
___________ 5.
This type of loop repeats as long as the user
needs to enter input.
___________ 6.
This type of function is one that is already
defined in C++ and is ready to use.
Last Name:____________________
3
___________ 7.
A do while loop is called this due to the fact that the body executes first
ather than the expression.
___________ 8.
This allows us to redefine the scope of a function so that we may define it
elow main.
___________ 9.
In this stage of the Waterfall Model, the app is checked and executed to
ensure there are no e
ors in the program.
___________ 10. This type of variable is one that can be used throughout the entire program.
___________ 11.
This type of loop repeats from a starting number to an ending number,
epeating a quantifiable number of times.
___________ 12. This is a type of variable that a function uses to store its input.
___________ 13. This phase of a for loop is where the counter variable is updated/changed.
___________ 14.
This type of e
or occurs when the code written in a program does not
follow the language’s syntactical rules.
___________ 15. This will make a function one that returns nothing back to where its called.
Last Name:____________________
4
16. Briefly describe 2 reasons why need functions. (6 pts)
17. List the stages of the for loop in the order that they execute and indicate whether each will
epeat on each round of the loop. (4 pts)
18. Describe an example of a syntactical e
or. Also describe an example of a logical e
or. (5 pts)
Last Name:____________________
5
Analysis
19. The following program has a total of 5 e
ors in it. List the line number of each e
or and
determine whether the e
or is a syntax or logical e
or. (5 pts)
Line 01: int larger(int a, int b);
Line 02:
Line 03:
Line 04: int main()
Line 05: {
Line 06: int a, int b, int c, int d, int e, int f;
Line 07:
Line 08: cout
"Enter 4 numbers: ";
Line 09: cin
a
b
c
d
e
f;
Line 10:
Line 11: cout
"Number 1: "
larger(a, f)
"\n";
Line 12: cout
"Number 2: "
larger(b, c)
"\n";
Line 13: cout
Number 3:
larger(f, d)
"\n";
Line 14: cout
"Number 3: "
larger(c, b)
"\n";
Line 15: cout
"Number 5: "
larger(a, a)
"\n";
Line 16: }
Line 17:
Line 18: int larger(int a, int b)
Line 19: {
Line 20: if (a < b)
Line 21: return a;
Line 22: else
Line 23: return b;
Line 24: }
Sample Output
Last Name:____________________
6

20. Read the following program and indicate the scope of each variable and function in it. Identify
whether each is local or global scope. (6 pts)
Line 01: int t = 20;
Line 02: int function_a(int x, int y);
Line 03:
Line 04: int main()
Line 05: {
Line 06: int j = 2;
Line 07:
Line 08: double l;
Line 09:
Line 10: for (int i = 0; i < 10; i++)
Line 11: {
Line 12: j = 0;
Line 13:
Line 14: do
Line 15: {
Line 16: j += 2;
Line 17:
Line 18: int d;
Line 19: cin
d;
Line 20:
Line 21: l = d;
Line 22:
Line 23: } while (j < 10);
Line 24: }
Line 25:
Line 26: int r = function_a(j, l);
Line 27:
Line 28: cout
r
" "
t
"\n";
Line 29: }
Line 30:
Line 31: int function_a(int x, int y)
Line 32: {
Line 33: int z = 0;
Line 34:
Line 35: for (int p = x; p < y; p++)
Line 36: {
Line 37: t += z;
Line 38: z = p + x - y;
Line 39: }
Line 40: return z;
Line 41: }
Last Name:____________________
7

21. Read the following snippets of code, which all contain loops. Determine the Loop Control
Variable in each loop and indicate the type of LCV it is, as well as the value(s) that the LCV would
need to be for the loop to terminate. (6 pts)
Code A

int i = 4;
while (i < 10)
{
i += 2;
cout
i
", ";
}
cout
"\n";
Code C

ool is_over = false;
int x = 34, y = 78;
int n;
do
{
cout
"Enter a number to add: ";
cin
n;
x += n;
if (x >= 78)
is_over = true;

} while(is_over == false);
Code B

int sum = 0;
int m = 0;
while(m >= 0)
{
cin
m;
sum += m;
}
Last Name:____________________
8

22. Read the following code:
a. Indicate the starting value of the counter for this for loop. (1 pt)
. Indicate the ending value of the counter for this for loop. (1 pt)
c. What is the output of this for loop? You only must output result up to XXXXXXXXXXpts)
d. What is the purpose of this program? (3 pts)
for(int num = 0; num < 100; num++)
{
if (num % 5 == 0 || num % 7 == 0)
cout
num
", ";
}
Last Name:____________________
9
Programming Problem
23. The following is a partially complete program that computes the total tax on a set of land,
measured in acres, by implementing a function called calc_tax. Complete the program by filling
in the missing lines of code. Comments have been left above each blank that give hints as to
what should be entered. Sample Output of the co
ectly completed program is given below.
1. Write a prototype for the calc_tax function that is defined after
main.
Hint: Complete part 3 before you complete this part.

_______________________________________________________________
int main()
{
double price_acre;

Ask the user for the price of 1 acre
cout
"What is the price per acre? ";
cin
price_acre;

Loop from 1 to 20 using a count-controlled loop
for (int i = 1; i <= 20; i++)
{

Format the number output to 2 decimal places.
cout
setprecision(2)
fixed;

2. Output the number of acres (i.e., i) and the total tax

owed on the acres. Look at the sample output at the end

of the program for how the output should be formatted.

Call the calc_tax function and pass in “i” for the acres

and “price_acre” for the number of acres.

Hint: Complete Part 3 Before completing this part.

__________________________________________________________
__________________________________________________________
}


}
Last Name:____________________
10

3. Begin the definition of a function called calc_tax. The tax
should output the total tax owed and create the following
parameters:
acres as decimal number
price_per_acre as a decimal number.


______________________________________________________________
{

Get the total monetary worth of the land.
double acres_worth = acres * price_per_acre;


Assessment value is 60% of the acres total worth;
double assessment_value = acres_worth * 0.6;

Total the tax amount, 73 cents per 100 acres.
double tax = 0;



4. Write a for loop header that would iterate as follows:

Start: 0

End: assessment_value

Increase the counter variable by 100.
________________________________________________________
{
tax += 0.73;
}

5. Output the calculated tax
Answered Same Day Nov 06, 2021

Solution

Neha answered on Nov 07 2021
145 Votes
CSC 101 Computer Science 1 –
Fall 2021
    Student Name:
         
    
School ID:
    
    
    
Section Number:
    
    
    
    Sections:
· H004
Test Breakdown
    Concept Knowledge
    60 %
    Program Analysis
    25 %
    Program Writing
    15 %
(
1
)
Grade:     
Concept Knowledge
Match the following definitions and statements to the terms listed on the right. Note that some terms may be used more than once while others may not be used at all. (3 pts each)
    
Design    
    
1.
    
In this stage of the Waterfall model, the app is planned, and the software requirements are mapped out.
    A. Logical
B. Release
C. Pre-Test
D. Body
E. Prototype
F. Sentinel Controlled Loop
G. Plan
H. Local Variable
I. Syntax
J. Pre-defined function
K. Post-Test
L. Return Type
M. Pseudocode
N. Develop
O. Void
P. Condition/Expression
Q. Test
R. Flowchart
S. Paramete
T. Initialization
U. Runtime
V. Design
W. Global Variable
X. Count Controlled Loop
Y. Step
    
Runtime    
    
2.
    
This type of e
or occurs when the operating system/computer cannot execute a line of code in a program.
    
    
Initialization
    
3.
    
This is the phase of a for loop where the counting variable in initialized/created.
    
    
Pseudocode
    
4.
    
This type of design approach involves creating a high level/informal description of a program that does not adhere to any particular programming language’s rules.
    
    
Sentinal Controlled Loop
    
5.
    
This type of loop repeats as long as the user needs to enter input.
    
    
Pre-defined function
    
6.
    
This type of function is one that is already defined in C++ and is ready to use.
    
(
Last

Name:

)
(
10
)
     True
    7.
    A do while loop is called this due to the fact that the body executes first
ather than the expression.
    
Predefined function
    
8.
    This allows us to redefine the scope of a function so that we may define it below main.
    
Test    
    
9.
    In this stage of the Waterfall Model, the app is checked and executed to ensure there are no e
ors in the program.
     Global variable
    10.
    This type of variable is one that can be used throughout the entire program.
    
Count controlled loop
    
11.
    This type of loop repeats from a starting number to an ending number, repeating a quantifiable number of times.
     Local variable
    12.
    This is a type of variable that a function uses to store its input.
    Condition     
    13.
    This phase of a for loop is where the counter variable is updated/changed.
    
Syntax e
or    
    
14.
    This type of e
or occurs when the code written in a program does not
follow the language’s syntactical rules.
     Return type
    15.
    This will make a function one that returns nothing back to where its called.
16. Briefly describe 2 reasons why need functions. (6 pts)
· The first reason is usability will stop once the function is defined we can use it again and again. We can invoke the same function multiple times in the program.
· Another reason is abstraction. If we want to use a particular function then it is important that we know the name of the function, it's working, arguments and the type of result which it is returning. Rest of the things needs to be hidden and abstraction helps to do that.
17. List the stages of the for loop in the order that they execute and indicate whether each will repeat on each round of the loop. (4 pts)
· The first stage is initialization. In this stage we introduce the variables which will be used in the program and the variables are initialized as zero or one.
· Test condition is second stage in which one of the counter...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here