MATLAB Answers

how can ı add the given instruction to my program?

77 ビュー (過去 30 日間)
matlab coder
matlab coder 2021 年 1 月 16 日
回答済み: Image Analyst 2021 年 1 月 16 日
clc; clear;
% Student numbers:
stu_nums = 20200001:20200102;
%% Randomly generated marks:
for i = 1:length(stu_nums)
stu(i).exam1 = randi([0 100]) ;
stu(i).exam2 = randi([0 100]) ;
stu(i).lab = randi([0 100]) ;
stu(i).fin_exm = randi([0 100]) ;
stu(i).fin_grd = round(stu(i).exam1*0.25 + stu(i).exam2*0.2 + stu(i).lab*0.15 + stu(i).fin_exm*0.4) ;
end
%% Finding non-failing students:
S = 0 ;
for i = 1:length(stu_nums)
if stu(i).fin_exm < 35 || stu(i).lab < 10
stu(i).let_grd = 'FF' ;
else
S = [S stu(i).fin_grd] ;
end
end
%% Mean of non-failing students' marks and standard deviation:
S(1) = [] ;
avg = mean(S) ;
st_dev = std(S) ;
%% Grade range:
CC = avg ;
% Starting points for upper grades:
CB = round(CC+st_dev/2) ;
BB = round(CB+st_dev/2) ;
BA = round(BB+st_dev/2) ;
AA = round(BA+st_dev/2) ;
% Ending points for lower grades:
DC = round(CC-st_dev/2) ;
DD = round(DC-st_dev/2) ;
FD = round(DD-st_dev/2) ;
FF = round(FD-st_dev/2) ;
%% Grade each student:
for i = 1:length(stu_nums)
if stu(i).fin_grd <= FF
stu(i).let_grd = 'FF' ;
elseif stu(i).fin_grd > FF && stu(i).fin_grd <= FD
stu(i).let_grd = 'FD' ;
elseif stu(i).fin_grd > FD && stu(i).fin_grd <= DD
stu(i).let_grd = 'DD' ;
elseif stu(i).fin_grd > DD && stu(i).fin_grd <= DC
stu(i).let_grd = 'DC' ;
elseif stu(i).fin_grd > DC && stu(i).fin_grd < CB
stu(i).let_grd = 'CC' ;
elseif stu(i).fin_grd >= CB && stu(i).fin_grd < BB
stu(i).let_grd = 'CB' ;
elseif stu(i).fin_grd >= BB && stu(i).fin_grd < BA
stu(i).let_grd = 'BB' ;
elseif stu(i).fin_grd >= BA && stu(i).fin_grd < AA
stu(i).let_grd = 'BA' ;
elseif stu(i).fin_grd >= AA
stu(i).let_grd = 'AA' ;
end
end
this is my computer program which would read these data and calculate the total grade for each student.
After the letter grades are calculated the program would ask the user what type of information is asked for. The program should ask the user whether the user wants to see overall grade distribution or grade information for an individual. Here my program should watch for invalid input. If the user enters an invalid input, the program should warn the user and ask for the input again until the user enters a valid input. In this phase the program should NOT stop until the user enters a valid input.
how can ı do that?

  0 件のコメント

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2021 年 1 月 16 日
Here is a snippet for user input that might help:
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'};
titleBar = 'Enter values';
userPrompt = {'Enter floating point number 1 : ', 'Enter floating point number 2: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check usersValue1 for validity.
if isnan(usersValue1)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end
% Do the same for usersValue2
% Check usersValue2 for validity.
if isnan(usersValue2)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue2.
usersValue2 = str2double(defaultValue{2});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue2);
uiwait(warndlg(message));
end
and here is one for asking user a question that might help
promptMessage = sprintf('Do you want to Continue processing,\nor Quit processing?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
return; % or break or continue.
end

  0 件のコメント

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by