Professional Documents
Culture Documents
'Problem1' 'A' 'Problem2' 'Bye' 'Hi' 'Hello' 'Problem3' 'Month' 'Day' 'Year' 'Problem4' '4.a' '4.b' 'Problem5'
'Problem1' 'A' 'Problem2' 'Bye' 'Hi' 'Hello' 'Problem3' 'Month' 'Day' 'Year' 'Problem4' '4.a' '4.b' 'Problem5'
'Problem1' 'A' 'Problem2' 'Bye' 'Hi' 'Hello' 'Problem3' 'Month' 'Day' 'Year' 'Problem4' '4.a' '4.b' 'Problem5'
%11/5/21
%CS 1972, Program 7
disp('Problem1')
buildstr('a',5)
disp('Problem2')
myca={'bye','hi','hello'};
caprint1(myca)
disp('Problem3')
st=struct('month',3,'day',30,'year',2021);
[m,d,y]=monthday(st)
disp('Problem4')
disp('4.a')
mathCourse
disp('4.b')
examAve(mathCourse)
disp('Problem5')
Quizdata
Buildstr
function output=buildstr(a,n)
output={a};
for i=2:n
output{i}=append(output{i-1},char(a+i-1));
end
end
caprint1
function caprint1(myca)
for i=1:length(myca)
if(strcmp(class(myca{i}),'char')==0)
disp('Sorry, not all strings!');
return;
end
end
for i=1:length(myca)
fprintf('String %d is: %s\n',i,myca{i});
end
end
monthday
function [m,d,y]=monthday(st)
m=st.month;
d=st.day;
y=st.year;
end
mathCourse
mathCourse(1).Name.First='Aee';
mathCourse(1).Name.Last='Kim';
mathCourse(1).ID=1111;
mathCourse(1).Exams=[99 80 70 89 85];
mathCourse(2).Name.First='Bob';
mathCourse(2).Name.Last='Epp';
mathCourse(2).ID=2222;
mathCourse(2).Exams=[88 76 68 87 96];
mathCourse(3).Name.First='Cyd';
mathCourse(3).Name.Last='Dee';
mathCourse(3).ID=3333;
mathCourse(3).Exams=[64 73 66 79 60];
examAve(mathCourse)
examAve
function examAve(mathCourse)
for i=1:length(mathCourse)
lname=mathCourse(i).Name.Last;
id=mathCourse(i).ID;
avg=mean(mathCourse(i).Exams);
fprintf('Last name: %5s\tID: %d\tAverage: %6.2f\n',lname,id,avg)
end
end
quizdata
load('quizscores.txt');
[r,c]=size(quizscores);
for i=1:r
students(i).id_no=quizscores(i,1);
for j=2:c
students(i).quiz(j-1)=quizscores(i,j);
end
end
fprintf('Student Quiz Ave\n')
for i=1:r
aveScore=mean([students(i).quiz]);
fprintf('%d %.1f\n',students(i).id_no,aveScore)
end
output
Program7
Problem1
ans =
Problem2
String 2 is: hi
Problem3
m=
3
d=
30
y=
2021
Problem4
4.a
mathCourse =
Name
ID
Exams
4.b
Problem5
44 7.5
33 6.0
37 8.0
24 7.0