) Assume that the following pseudocode is executed in a program: Module main Dec
ID: 3850008 • Letter: #
Question
)
Assume that the following pseudocode is executed in a program:
Module main
Declare x = 0
Declare sum = 0
Declare max = 4
While (x < max)
Display "x is ", x
Set x = x + 1
Set sum = sum + x
End While
End Module
2) After the execution of this program, the final value of x is _______, and the final value of sum is ______
Write the program segment that includes a loop that will loop 5 times. With each iteration, ask the user for a number, and accumulate the sum. After the loop, print the sum of the numbers
3)
Looping Problem with If/Then/Else
A country club dues report is to be prepared. Pseudocode only using modules and the auto EOF DOWHILE loop.
Inputs consist of records containing the Country Club member’s name, the type of membership, and the years the member has belonged. The value F in the individual membership type field indicates a family membership. The value I indicates an individual membership. The input data is illustrated below.
NAME
MEMBERSHIP TYPE
YEARS
Harvey Hanley
F
9
Wilma Litt
F
7
Eugene Mitter
F
2
Wall Pitt
I
6
Eunice Ponnir
I
8
Output is a list of the country club members containing the member’s name, the membership type (FAMILY or INDIVIDUAL), the years the member has belonged, and the country club dues. The dues are calculated as follows: If the member is a family member and has been a member more than six years, the dues are $1,200.00. If the member is a family member and has been a member six years or less, the dues are $1,600.00. If the member is an individual member and has been a member longer than 6 years, the country club dues are $800.00. If the member is an individual member and has been a member 6 years or less, the dues are $1,100.00. After all records have been printed, totals for the number of members, the number of family members, the number of individual members, and the total dues are to be printed.
NAME
MEMBERSHIP TYPE
YEARS
Harvey Hanley
F
9
Wilma Litt
F
7
Eugene Mitter
F
2
Wall Pitt
I
6
Eunice Ponnir
I
8
Explanation / Answer
************QUESTION 2 PART A***************
//THE GIVEN PROGRAM implements the above pseudo-code in C language.
//The FINAL VALUE of X is 4 and the FINAL VALUE of SUM is 4.
#include<stdio.h>
int main(){
int x=0; // Declare x = 0
int sum=0; // Declare sum = 0
int max=4; // Declare max = 4
while(x<max){ //While (x < max)
printf("x is %d ", x); //Display "x is ", x
x=x+1; //Set x = x + 1
sum=sum+1; //Set sum = sum + x
} //End While
//PRINT FINAL VALUES
printf("Final value of x = %d and sum = %d", x, sum);
return 0;
}
***********QUESTION 2 PART B***************
//THE GIVEN PROGRAM ASKS THE USER FOR A NUMBER AND ACCUMULATES THE SUM.
-----PSEUDO-CODE-----
Declare input = 0
Declare sum = 0
Start loop using for loop -> for(i=0;i<5;i++)
Take input and store in the variable input.
Set sum=sum+input
End For Loop
Print Final Sum
CODE
#include<stdio.h>
int main(){
int input=0; // Declare input = 0
int sum=0; // Declare sum = 0
int i=0;
for(i=0;i<5;i++){ // LOOP 5 times
scanf("%d", &input); //TAKE AN INPUT
sum=sum+input; //Set sum = sum + Input
} // End Loop
//PRINT FINAL SUM
printf("The sum of numbers is %d", sum);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.