for algorithm only!! This lab requires you to think about the steps that take pl
ID: 3881451 • Letter: F
Question
for algorithm only!! This lab requires you to think about the steps that take place in a program by writing algorithms. Read the following program prior to completing the lab
Write a program that will take in basic information from a student, including student name, degree name, number of credits taken so far, and the total number of credits required in the degree program. The program will then calculate how many credits are needed to graduate. Display should include the student name, the degree name, and credits left to graduate.
Step 1: Examine the following algorithm.
Get the student name.
Get the degree program name.
Subtract the number of credits taken so far from the required credits for the degree.
Get the number of credits required for the degree program.
Get the number of credits the student has taken so far.
Display the input information in Step 1 and 2.
Display the calculated information.
Step 2: What logic error do you spot and how would you fix it?
Step 3: What steps require user interaction (Ex: user must type in some input)?
Explanation / Answer
logic error is at line 3 of the algorithm
at line 3, with out getting the inforamtaion about number of credits so far and total credits we are subtracting, so this is the error...
correct sequence would be:
1:Get the student name.
2:Get the degree program name.
3:Get the number of credits required for the degree program.
4:Get the number of credits the student has taken so far.
5:Subtract the number of credits taken so far from the required credits for the degree.
6:Display the input information in Step 1 and 2.
7:Display the calculated information.
steps 1,2,3,4 requires user interaction
program:
#include<iostream>
using namespace std;
int main()
{
//variable declaration
string name,degree_name;
double number_credits, total_credits;
//taking input
//Get the student name.
cout<<"Enter student name:";
cin>>name;
//Get the degree program name.
cout<<"Enter degree name:";
cin>>degree_name;
//
//Get the number of credits required for the degree program.
cout<<"Enter total credits requires :";
cin>>total_credits;
//Get the number of credits the student has taken so far.
cout<<"Enter number of credits taken so far:";
cin>>number_credits;
//Subtract the number of credits taken so far from the required credits for the degree.
int m = total_credits-number_credits;
//Display the input information in Step 1 and 2.
cout<<"Name :"<<name<<endl;
cout<<"DegreenName :"<<degree_name<<endl;
//Display the calculated information.
cout<<"Credits need to finsh course:"<<m<<endl;
return 0;
}
output:
Enter student name:surya
Enter degree name:cse
Enter total credits requires :100
Enter number of credits taken so far:60
Name :surya
DegreenName :cse
Credits need to finsh course:40
Process exited normally.
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.