需要伪代码分配方面的帮助!关于阅读记录并添加和打印
学生记录文件包含每个学生的姓名、性别(男或女)、年龄(年份)和婚姻状况(单身或已婚)。设计一个算法来读取文件并计算已婚男性、单身男性和已婚女性的数量。将这些数字打印在学生总结报告上。如果有30岁以上的单身男性。在单独的合格单身汉报告上打印他们的姓名和年龄。
谁能告诉我我是否有任何错误?谢谢!希望你能帮助我!
Set marriedMen to 0
Set singleMen to 0
Set marriedWomen to 0
Set singleWomen to 0
READ name, sex, age, status
DOWHILE(NOT EOF)
IF (status = married) THEN //check if status is married, if yes then check next
IF (sex = ‘F’) THEN //check if sex is F, if yes then +1
marriedWomen = marriedWomen + 1
ELSE
IF (sex = ‘M’) THEN //under married, and sex is M then +1
marriedMen = marriedMen + 1
ENDIF
ENDIF
ENDIF
IF (status = single) THEN //check if status is single, if yes then check next
IF (sex = ‘F’) THEN //check if sex is F, if yes then +1 to singleWomen
singleWomen = singleWomen + 1
ELSE
IF (sex = ‘M’) THEN //under single, and sex is M then +1
singleMen = singleMen + 1
IF (age > 30) THEN //under single, sex = M and age is over 30 then print the name, age
Print ‘Eligible bachelors Report’
Print ‘Name: ‘, name
Print ‘Age: ‘, age
ENDIF
ENDIF
ENDIF
ENDIF
READ next record
ENDDO
Print ‘Student Summary Report’
Print ‘Married Men: ‘, marriedMen
Print ‘Single Men: ‘, singleMen
Print ‘Married Women: ‘, marriedWomen
Print ‘Single Women: ‘, singleWomen
A file of student records contains name, gender (M or F), age (in year) and marital status (single or married) for each student. Design an algorithm that will read through the file and calculate the number of married men, single men, and married women. Print these numbers on a student summary report. If any single men are over 30 year of age. Print their names and ages on a separate eligible bachelors report.
Can anyone tell me if I am wrong in any line? thanks! hope you can help me!
Set marriedMen to 0
Set singleMen to 0
Set marriedWomen to 0
Set singleWomen to 0
READ name, sex, age, status
DOWHILE(NOT EOF)
IF (status = married) THEN //check if status is married, if yes then check next
IF (sex = ‘F’) THEN //check if sex is F, if yes then +1
marriedWomen = marriedWomen + 1
ELSE
IF (sex = ‘M’) THEN //under married, and sex is M then +1
marriedMen = marriedMen + 1
ENDIF
ENDIF
ENDIF
IF (status = single) THEN //check if status is single, if yes then check next
IF (sex = ‘F’) THEN //check if sex is F, if yes then +1 to singleWomen
singleWomen = singleWomen + 1
ELSE
IF (sex = ‘M’) THEN //under single, and sex is M then +1
singleMen = singleMen + 1
IF (age > 30) THEN //under single, sex = M and age is over 30 then print the name, age
Print ‘Eligible bachelors Report’
Print ‘Name: ‘, name
Print ‘Age: ‘, age
ENDIF
ENDIF
ENDIF
ENDIF
READ next record
ENDDO
Print ‘Student Summary Report’
Print ‘Married Men: ‘, marriedMen
Print ‘Single Men: ‘, singleMen
Print ‘Married Women: ‘, marriedWomen
Print ‘Single Women: ‘, singleWomen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在下面的代码中,我执行了以下操作:
'
替换为'
,因为您显然使用了文字处理器(例如 MS-Word)来编写代码。 (我可以建议 NotePad++ 吗?)我保留了你的代码大部分完整:我理所当然地认为
ElseIf
不是伪代码中的有效关键字,并且您的教授可能会向您传递一个性别除M
和F< 以外的文件/代码>。
In the code below, I have done the following:
boolean
to prevent you from printing yourEligible bachelors Report
header for every single line.‘
with'
because you obviously used a word processor such as MS-Word to write your code. (May I suggest NotePad++?)I left your code mostly intact: I take it for granted that
ElseIf
isn't a valid keyword in your pseudo code and that your professor might pass you a file with genders other thanM
andF
.DrawTree(n, 方向, 长度)
end DrawTree
DrawTree(n, direction, length)
end DrawTree