需要伪代码分配方面的帮助!关于阅读记录并添加和打印

发布于 2024-12-03 01:59:55 字数 1275 浏览 0 评论 0原文

学生记录文件包含每个学生的姓名、性别(男或女)、年龄(年份)和婚姻状况(单身或已婚)。设计一个算法来读取文件并计算已婚男性、单身男性和已婚女性的数量。将这些数字打印在学生总结报告上。如果有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳钉梦 2024-12-10 01:59:55

在下面的代码中,我执行了以下操作:

  1. 添加了一个布尔值,以防止您打印每一行的“合格单身汉报告”标题。
  2. 缩进您的代码,使其更易于阅读。
  3. ' 替换为 ',因为您显然使用了文字处理器(例如 MS-Word)来编写代码。 (我可以建议 NotePad++ 吗?)

我保留了你的代码大部分完整:我理所当然地认为 ElseIf 不是伪代码中的有效关键字,并且您的教授可能会向您传递一个性别除 MF< 以外的文件/代码>。

Set marriedMen to 0
Set singleMen to 0
Set marriedWomen to 0
Set singleWomen to 0 
Set hasPrintedHeader to False

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
                    IF (hasPrintedHeader = False) THEN
                        Print 'Eligible bachelors Report'
                        hasPrintedHeader = True
                    END IF
                    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

In the code below, I have done the following:

  1. Added a boolean to prevent you from printing your Eligible bachelors Report header for every single line.
  2. Indented your code so it is easier to read.
  3. Replaced your use of 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 than M and F.

Set marriedMen to 0
Set singleMen to 0
Set marriedWomen to 0
Set singleWomen to 0 
Set hasPrintedHeader to False

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
                    IF (hasPrintedHeader = False) THEN
                        Print 'Eligible bachelors Report'
                        hasPrintedHeader = True
                    END IF
                    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
梦言归人 2024-12-10 01:59:55

DrawTree(n, 方向, 长度)

if n > 0 do

    DrawTrunk(direction, length)

    DrawTree(n-1, 3DRandomAngle(direction), length*Factor(n))

    DrawTree(n-1, direction + random % 10, length*Factor(n))

    DrawTree(n-1, 3DRandomAngle(direction), length*Factor(n))

else

    DrawLeaf()

end if

end DrawTree

DrawTree(n, direction, length)

if n > 0 do

    DrawTrunk(direction, length)

    DrawTree(n-1, 3DRandomAngle(direction), length*Factor(n))

    DrawTree(n-1, direction + random % 10, length*Factor(n))

    DrawTree(n-1, 3DRandomAngle(direction), length*Factor(n))

else

    DrawLeaf()

end if

end DrawTree

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文