Question
In Matlab. Use loops.
2. Create an algorithm to allow the user to enter a list of courses they have taken along with the grades received and the credit hours for each course, and then calculate the users GPA. The program should first ask the user to type either Yes or No in response to the question, Do you want to enter a grade? If the answer is Yes, the user should be asked to enter the name of the course (text), the grade in the course (A, B, C, D, or F), and the number of credit hours for the course (a positive integer). If the user enters an invalid grade or an invalid number for the credit hours, he or she should be warned and asked to try again a maximum of th an appropriate error message should be generated and the program terminated. If they successfully enter the information for a course, the course name, the letter grade, and the credit hours should be displayed in a single row on the screen in an appropriate format, and then they should be asked again if they wish to enter a grade, and the entire process repeats if they answer Yes. If they answer No, the GPA should be calculated and displayed in an appropriate format, and then the program terminated unless no grades were entered (they typed No the first time) in which case an appropriate message should be generated and the program terminated. ree times, after which
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the required MATLAB code below along with necessary details in comments:

clear all
clc

% prompt user to enter the choice
prompt= '\nDo you wish to enter grade (Yes/No):';
decision=input(prompt,'s');

decision=lower(decision); % convert the response to lower case
count=0; % no. of subject whose info has been sucessfully eneterd

while strcmp(decision,'yes'); % if the choice to enter is yes
trail=1; % attempt one to enter the data
flag=0; % indicate the sucessfull attempt to enter info. flag=0 indicate data has not been entered
while flag~=1 && (trail==1 || trail==2 || trail==3)
flag=0;
% eneter the subject info
subject=input('\nEnter the name of subject:','s');
grade=input('\nEnter the grade (A-F):','s');
grade=upper(grade); % convert th grade to upper case
  
% if grade eneterd is not correct, issue a warning and repeat the process
if isempty(grade) || (~strcmp(grade,'A')&& ~strcmp(grade,'B')&& ~strcmp(grade,'C')&& ~strcmp(grade,'D') && ~strcmp(grade,'E')&& ~strcmp(grade,'F'))
warning('\nNot a valid grade. Please try again!');
trail=trail+1;
flag=0;
continue;
else
flag=1; % turn flag to 1 to indicate sucess status
end
  
% enter credit hour infomation
credit_hours=input('\nEnter the number of Credit hours:');
if isempty(credit_hours) || credit_hours<0
warning('\nCredit hours can not be negative. Please try again!');
flag=0;
trail=trail+1;
continue;
else
flag=1;
end
  
end
  
% check if information has been sucessfully enterd or not
if flag==0
fprintf('\nInvalid information. Terminating...');
break;
else % display the collected information
count=count+1;
fprintf('\nCourse \t Grade \t Credits\n');
fprintf('%s \t %s \t %3.2f',subject,grade,credit_hours);
Final_subject{count,1}=subject;
Final_grade(count,1)=grade;
Final_credit(count,1)=credit_hours;
end
  
decision=input(prompt,'s'); % ask user if he/she want to enter more data
decision=lower(decision);
  
end

% if user has stopped enetering new data
if ~strcmp(decision,'yes') && count~=0
% display the collected data
fprintf('\n The data entered is as follows:\n');
fprintf('\nCourse \t Grade \t Credits\n');
  
for k=1:size(Final_grade,1)
fprintf('\n%s \t %s \t %3.2f',Final_subject{k,1},Final_grade(k,1),Final_credit(k,1));
% find corresponding grade point for each grade
if strcmp(Final_grade(k,1),'A')
grade_point(k,1)=10;
elseif strcmp(Final_grade(k,1),'B')
grade_point(k,1)=9;
elseif strcmp(Final_grade(k,1),'C')
grade_point(k,1)=8;
elseif strcmp(Final_grade(k,1),'D')
grade_point(k,1)=7;
elseif strcmp(Final_grade(k,1),'E')
grade_point(k,1)=6;
else
grade_point(k,1)=10;
end
end
  
fprintf('\n GPA: %3.2f',mean(grade_point)); % report grade point average
  
end

------------------------ SCREENSHOT OF CODE

main script.m+ 1clear all 2-clc 5- 6- prompt user to enter the choice prompt- \nDo you wish to enter grade decision-input (p

31 32 8 enter credit hour infomation credit hours-input (AnEnter the number of Credit hours:): if isempty (credit_hours) II61 62 63- 64 65- 66 - 67 68- 69 70 If user has stopped enetering new data if ~stremp (decision, yes) “count 。 % display the

----------------------------------- SAMPLE OUTPUT

TEST CASE 1:

Command Window Do you wish to enter grade:yes Enter the name of subject Economics Enter the grade:A Enter the number of Credi

Computers B 6.00 GPA: 9.50>>

TEST CASE 2:

Command Window Do you wish to enter grade: Yes Enter the name of subject:maths Enter the grade:g Warning: InNot a valid grade

Enter the name of subject:english Enter the grade:a Enter the number of Credit hours:-4 Warning: InCredit hours can not be ne

Add a comment
Know the answer?
Add Answer to:
In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Matlab a) Write a MATLAB code that takes the grade letters from the user and provide him/her with the GPA for that seme...

    Matlab a) Write a MATLAB code that takes the grade letters from the user and provide him/her with the GPA for that semester Enter your grades (letters): AABBC (input) Your GPA is 3.2 output) b) Write a Matlab user defined function to that takes a letter grade and return a numeric grade as shown in the table below. Any other value should give an error message (Invalid Grade). You function name should be Letter2Grade Use the following information to calculate...

  • write inputs and outputs declare variables promt user b. Modify the program written for Exercise 9a...

    write inputs and outputs declare variables promt user b. Modify the program written for Exercise 9a to determine wener e eReTeO evenly divisible by a user-specified value, with no remainder. That is, is it evenly divisible by 3, 7, 13, or any other user-specified value? 10. (Data processing) As a part-time student, you took two courses last term. Write, run, and test a C++ program that calculates and displays your grade point average (GPA) for the term. Your program should...

  • Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user...

    Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user login system. Your code should do the following: 3, create-user_name() #use this function to create the user name 1.Create your user database called "UD.txt", this should be in CSV format 4, write-file() #user this function to save the user name and password into "UD.txt" Deliverables: Sample: the data you saved...

  • This is a simple program that I'm struggling with. Java is not my forte... It's way...

    This is a simple program that I'm struggling with. Java is not my forte... It's way too verbose for my liking. Anyways... The criteria for the prog is as follows: No issues with the GUI, I can do this on my own, but for a reference see the following: A combo box should allow the user to select one of the four database actions shown. The database should be implemented as a HashMap, with the ID field as the key...

  • I) will create a rudimentary (and highly insecure) database for the storage of only the user...

    I) will create a rudimentary (and highly insecure) database for the storage of only the user generated identities. This program will have the following behaviors: (line break, 11 pt) ) - Prior to prompting for a new username, the existing list of usernames should be read and loaded to an array. 1 ) Read the list from "users.txt", a prompt is not necessary. Do not change this data file name "users.txt". 2 ) The existing list of usernames should be...

  • 12.8 GPA reports using files Prompt the user by "Enter name of input file: " for...

    12.8 GPA reports using files Prompt the user by "Enter name of input file: " for the name of an input file and open that file for reading. The two input files for the tests are already at the zyBooks site.They each have a list of student names with the course they have taken, of the form Jacobs, Anthony ECS10 4 B- ECS20 4 C+ ANS17 3 A ANS49H 2 D Wilson, Elaine ECS10 4 B+ ECS20 4 C+ ANS17...

  • RandomGame.cpp (2pt) Write a program that asks the user to enter his/her name. Then begin a...

    RandomGame.cpp (2pt) Write a program that asks the user to enter his/her name. Then begin a do while loop that asks the user to enter a number between 1 and 10. Have the random number generator produce a number 1 and 10. Display the user’s name and both numbers to the screen. Compare the two numbers and report if the entered number is greater than, less than, or the same as the generated number. Ask the user if he/she’d like...

  • In Matlab Create a single script (.m file) to solve these problems. Unless directed otherwise, use...

    In Matlab Create a single script (.m file) to solve these problems. Unless directed otherwise, use meaningful variable names for each variable; do not use the default variable ans to store your results. For this project, suppress your output with semi-colons (;). Each problem should be in a separate cell, using the cell mode feature of MATLAB. Problem 4 Video games are rather complicated to program, not least of which because of the graphics work that needs to be completed...

  • Java Data Structures

    Programming Instructions:Using      Java Object Oriented Principles, write a program which produces the      code as indicated in the following specifications: Your       program must be a console application that provides a user this exact       menu:Please select one of the following:1: Add Client to Bank2: Display Clients in the Bank3: Set Bank Name4: Search for a Client5: Exit Enter your Selection: <keyboard input here> The       menu must be displayed repeatedly until 5...

  • Write a C program that allows a user to enter up to 30 student id’s and...

    Write a C program that allows a user to enter up to 30 student id’s and 3 grades per student. It will then compute and display a report of the students averages, and then a statement of the class average for those grades. The following is a sample run that demonstrates what your program should look like: Please enter your school name: Cape Tech Welcome to the Cape Tech Grade Calculator Enter the number of students to process (0 -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT