'Problem1' 'A' 'Problem2' 'Bye' 'Hi' 'Hello' 'Problem3' 'Month' 'Day' 'Year' 'Problem4' '4.a' '4.b' 'Problem5'

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

%Jeriah Jordan

%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 =

1×5 cell array

{'a'} {'ab'} {'abc'} {'abcd'} {'abcde'}

Problem2

String 1 is: bye

String 2 is: hi

String 3 is: hello

Problem3

m=

3
d=

30

y=

2021

Problem4

4.a

mathCourse =

1×3 struct array with fields:

Name

ID

Exams

4.b

Last name: Kim ID: 1111 Average: 84.60

Last name: Epp ID: 2222 Average: 83.00

Last name: Dee ID: 3333 Average: 68.40

Problem5

Student Quiz Ave

44 7.5

33 6.0
37 8.0

24 7.0

You might also like