Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
problem on the main program Posted by rrwe on 13 Jan 2012 at 5:46 AM
the following cannot be ran as the sample output shown :
F: (0)
E:** (2)
D:****** (6)
C:*********(9)
B:**** (4)
A:**(2)

how can solved this problem?
many thanks to you guys


program barchart;
var
   count : array ['A'..'F'] of integer;
   mark : array [1..15] of integer;
   i: integer;
   ch: char;

procedure countgrade;
var
   ch : char;
   i : integer;
begin
   for ch := 'A' to 'F' do
       count[ch] := 0;
   for i := 1 to 15 do
       case mark[i] of
	      0..50 : count['F'] := count['F'] + 1;
	      51..60 : count['E'] := count['E'] + 1;
	      61..70 : count['D'] := count['D'] + 1;
	      71..80 : count['C'] := count['C'] + 1;
	      81..90 : count['B'] := count['B'] + 1;
	      91..100 : count['A'] := count['A'] + 1;
       end
end;

procedure plotchart;
var
   ch : char;
   i : integer;
begin
   for ch := 'F' to 'A' do
   begin
      write(ch, ':');
      for i := 1 to count[ch] do
         write('*');
      writeln('(', count[ch], ')')
   end
end;

begin
   for i:=1 to 15 do
      begin
         write('Enter test mark for student ',i,': ' );
         readln(mark[i]);
      end;

   countgrade;
   plotchart;
   readln
end.
Report
Re: problem on the main program Posted by Actor on 13 Jan 2012 at 6:44 PM
How many students can the program accommodate? How many marks?

Look at the loop in procedure plotchart; how does it terminate?

:
: 
: program barchart;
: var
:    count : array ['A'..'F'] of integer;
:    mark : array [1..15] of integer;
:    i: integer;
:    ch: char;
: 
: procedure countgrade;
: var
:    ch : char;
:    i : integer;
: begin
:    for ch := 'A' to 'F' do
:        count[ch] := 0;
:    for i := 1 to 15 do
:        case mark[i] of
: 	      0..50 : count['F'] := count['F'] + 1;
: 	      51..60 : count['E'] := count['E'] + 1;
: 	      61..70 : count['D'] := count['D'] + 1;
: 	      71..80 : count['C'] := count['C'] + 1;
: 	      81..90 : count['B'] := count['B'] + 1;
: 	      91..100 : count['A'] := count['A'] + 1;
:        end
: end;
: 
: procedure plotchart;
: var
:    ch : char;
:    i : integer;
: begin
:    for ch := 'F' to 'A' do { how does this loop terminate? }
:    begin
:       write(ch, ':');
:       for i := 1 to count[ch] do
:          write('*');
:       writeln('(', count[ch], ')')
:    end
: end;
: 
: begin
:    for i:=1 to 15 do
:       begin
:          write('Enter test mark for student ',i,': ' );
:          readln(mark[i]);
:       end;
: 
:    countgrade;
:    plotchart;
:    readln
: end.
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.