musadoto ©2018 slideshare2
AE 219-COMPUTER PROGRAMING TEST 2017 MANUAL SOLUTION
1.Write a program to describe the weather according to the following
temperature Classifications:
Temperature, T(O
C) Classification
T>40 Very Hot
T>25 and T≤40 HOT
T>20 and T≤25 Cool
T>3 and T≤20 Cold
T≤3 Freezing
answer
PROGRAM WeatherTester(INPUT,OUTPUT);
VAR
Temperature :INTEGER;
VeryHot, Hot, Cool, Cold, Freezing :BOOLEAN;
BEGIN
WRITE('Please enter the temperature:');
READLN(Temperature);
VeryHot := (Temperature > 40);
Hot := (Temperature > 25) AND (Temperature <= 40);
Cool := (Temperature > 20) AND (Temperature <= 25);
Cold := (Temperature > 3) AND (Temperature <= 20);
Freezing := (Temperature <= 3);
WRITELN;
IF VeryHot THEN
WRITELN('Very Hot')
ELSE IF Hot THEN
WRITELN('Hot')
ELSE IF Cool THEN
WRITELN('Cool')
ELSE IF Cold THEN
WRITELN('cold')
ELSE IF Freezing THEN
WRITELN('freezing')
ELSE
{ End of the IF construct }
WRITELN('Press ENTER to continue..');
READLN
END.
musadoto ©2018 slideshare2
2.Write the output of the program below using exponent values from 1 - 20.
PROGRAM Prog_Q2;
VAR
Base, Power, Start, Final :INTEGER;
BEGIN
Base := 2;
WRITE('Enter starting exponent:');
READLN(Start);
WRITE('Enter ending exponent:');
READLN(Final);
WRITELN;
WRITELN('Number Power of two');
FOR Power := Start TO Final DO
BEGIN
WRITE(Power:3);
WRITELN(EXP(LN(Base)*Power):20:0)
END;
WRITELN;
WRITELN('Press ENTER to continue..');
READLN
END. {Prog_Q2}
Answer
Enter starting exponent:1
Enter ending exponent:20
Number Power of two
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
9 512
10 1024
11 2048
12 4096
13 8192
14 16384
15 32768
16 65536
17 131072
18 262144
19 524288
20 1048576
Press ENTER to continue..
3.Write the output of the following program with the following input data
45 3 60
45 5 60
45 6 60
Comment on the results (outputs)
musadoto ©2018 slideshare2
PROGRAM Prog_Q3;
Const
g=9.8;{acceleration due to gravity}
Pi=3.1415927;{a well-known constant}
var
A:integer; {launch angle in degrees}
T:integer; {time of flight}
Theta:integer; {direction at time T in degrees}
U:integer; {launch velocity}
V:integer; {resultant Velocity}
Vx:integer; {horizontal Velocity}
Vy:integer; {vertical velocity}
X:integer; {horizontal displacement}
Y:integer; {vertical displacement}
begin
write(‘Enter launch angle(A),time of flight(T),and launch
velocity(U):’);
READ(A,T,U);
A:=ROUND(A*Pi/180); {Convert angle to radians}
X:=ROUND(U*COS(A)*T);
Y:=ROUND(U*SIN(A)*T-g*T*T/2);
Vx:=ROUND(U*COS(A));
Vy:=ROUND(U*SIN(A)-g*T);
V:=ROUND(SQRT(Vx*Vx+Vy*Vy));
Theta:=ROUND(ARCTAN(Vy/Vx)*180/Pi);
Writeln(‘x:’, X:10,’ ’,‘y:’,Y:10);
Writeln(‘v:’, V:10,’ ’,‘Theta:’,Theta:5);
end.{prog_Q3}
Answers
RUN 1
Enter launch angle(A),time of flight(T),and launch velocity(U):45 3 60
X: 97 y: 107
V: 38 Theta 33
RUN 2
Enter launch angle(A),time of flight(T),and launch velocity(U):45 5 60
X: 162 y: 130
V: 32 Theta 2
RUN 3
Enter launch angle(A),time of flight(T),and launch velocity(U):45 6 60
X: 195 y: 127
V: 33 Theta -14
musadoto ©2018 slideshare2
4.Write the output of the program below for the following inputs
40.0 10.0
0.0 15.0
60.0 15.0
70.0 15.0
-1.0 0.0
PROGRAM Prog_Q4;
{Repetitive pay algorithm}
CONST
WeekHours = 7 * 24;{hours in a week}
VAR
Hours, Rate, Pay :REAL;
BEGIN
Write(‘Enter number of hours and rate ’);
Read(hours, rate);
WHILE Hours >= 0 DO
BEGIN
IF(Hours < 0) OR (Hours > WeekHours) THEN
Writeln(‘Errors in hours’)
ELSE
BEGIN
IF Hours <= 60 THEN
IF Hours <= 40 THEN
Pay := Hours * Rate
ELSE
Pay := 40 * Rate + 1.5 * Rate * (Hours - 40)
ELSE
Pay := 70 * Rate + 2 * Rate * (Hours - 60);
Writeln(‘The pay is ’,Pay:7:2);
END;{IF}
Write(‘Enter number of hours and rate ’);
Read(hours, Rate);
END;{WHILE}
END.{Prog_Q4}
Answer
Enter number of hours and rate 40.0 10.0
The Pay is 400.00
Enter number of hours and rate 00.0 15.0
The Pay is 0.00
Enter number of hours and rate 60.0 15.0
The Pay is 1050.00
Enter number of hours and rate 70.0 15.0
The Pay is 1350.00
Enter number of hours and rate -1.0 0.0
Errors in Hours
Note for ‘ and ’
SOLUTIONS BY FRIENDS

Ae 219 - BASICS OF PASCHAL PROGRAMMING-2017 test manual solution

  • 1.
    musadoto ©2018 slideshare2 AE219-COMPUTER PROGRAMING TEST 2017 MANUAL SOLUTION 1.Write a program to describe the weather according to the following temperature Classifications: Temperature, T(O C) Classification T>40 Very Hot T>25 and T≤40 HOT T>20 and T≤25 Cool T>3 and T≤20 Cold T≤3 Freezing answer PROGRAM WeatherTester(INPUT,OUTPUT); VAR Temperature :INTEGER; VeryHot, Hot, Cool, Cold, Freezing :BOOLEAN; BEGIN WRITE('Please enter the temperature:'); READLN(Temperature); VeryHot := (Temperature > 40); Hot := (Temperature > 25) AND (Temperature <= 40); Cool := (Temperature > 20) AND (Temperature <= 25); Cold := (Temperature > 3) AND (Temperature <= 20); Freezing := (Temperature <= 3); WRITELN; IF VeryHot THEN WRITELN('Very Hot') ELSE IF Hot THEN WRITELN('Hot') ELSE IF Cool THEN WRITELN('Cool') ELSE IF Cold THEN WRITELN('cold') ELSE IF Freezing THEN WRITELN('freezing') ELSE { End of the IF construct } WRITELN('Press ENTER to continue..'); READLN END.
  • 2.
    musadoto ©2018 slideshare2 2.Writethe output of the program below using exponent values from 1 - 20. PROGRAM Prog_Q2; VAR Base, Power, Start, Final :INTEGER; BEGIN Base := 2; WRITE('Enter starting exponent:'); READLN(Start); WRITE('Enter ending exponent:'); READLN(Final); WRITELN; WRITELN('Number Power of two'); FOR Power := Start TO Final DO BEGIN WRITE(Power:3); WRITELN(EXP(LN(Base)*Power):20:0) END; WRITELN; WRITELN('Press ENTER to continue..'); READLN END. {Prog_Q2} Answer Enter starting exponent:1 Enter ending exponent:20 Number Power of two 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024 11 2048 12 4096 13 8192 14 16384 15 32768 16 65536 17 131072 18 262144 19 524288 20 1048576 Press ENTER to continue.. 3.Write the output of the following program with the following input data 45 3 60 45 5 60 45 6 60 Comment on the results (outputs)
  • 3.
    musadoto ©2018 slideshare2 PROGRAMProg_Q3; Const g=9.8;{acceleration due to gravity} Pi=3.1415927;{a well-known constant} var A:integer; {launch angle in degrees} T:integer; {time of flight} Theta:integer; {direction at time T in degrees} U:integer; {launch velocity} V:integer; {resultant Velocity} Vx:integer; {horizontal Velocity} Vy:integer; {vertical velocity} X:integer; {horizontal displacement} Y:integer; {vertical displacement} begin write(‘Enter launch angle(A),time of flight(T),and launch velocity(U):’); READ(A,T,U); A:=ROUND(A*Pi/180); {Convert angle to radians} X:=ROUND(U*COS(A)*T); Y:=ROUND(U*SIN(A)*T-g*T*T/2); Vx:=ROUND(U*COS(A)); Vy:=ROUND(U*SIN(A)-g*T); V:=ROUND(SQRT(Vx*Vx+Vy*Vy)); Theta:=ROUND(ARCTAN(Vy/Vx)*180/Pi); Writeln(‘x:’, X:10,’ ’,‘y:’,Y:10); Writeln(‘v:’, V:10,’ ’,‘Theta:’,Theta:5); end.{prog_Q3} Answers RUN 1 Enter launch angle(A),time of flight(T),and launch velocity(U):45 3 60 X: 97 y: 107 V: 38 Theta 33 RUN 2 Enter launch angle(A),time of flight(T),and launch velocity(U):45 5 60 X: 162 y: 130 V: 32 Theta 2 RUN 3 Enter launch angle(A),time of flight(T),and launch velocity(U):45 6 60 X: 195 y: 127 V: 33 Theta -14
  • 4.
    musadoto ©2018 slideshare2 4.Writethe output of the program below for the following inputs 40.0 10.0 0.0 15.0 60.0 15.0 70.0 15.0 -1.0 0.0 PROGRAM Prog_Q4; {Repetitive pay algorithm} CONST WeekHours = 7 * 24;{hours in a week} VAR Hours, Rate, Pay :REAL; BEGIN Write(‘Enter number of hours and rate ’); Read(hours, rate); WHILE Hours >= 0 DO BEGIN IF(Hours < 0) OR (Hours > WeekHours) THEN Writeln(‘Errors in hours’) ELSE BEGIN IF Hours <= 60 THEN IF Hours <= 40 THEN Pay := Hours * Rate ELSE Pay := 40 * Rate + 1.5 * Rate * (Hours - 40) ELSE Pay := 70 * Rate + 2 * Rate * (Hours - 60); Writeln(‘The pay is ’,Pay:7:2); END;{IF} Write(‘Enter number of hours and rate ’); Read(hours, Rate); END;{WHILE} END.{Prog_Q4} Answer Enter number of hours and rate 40.0 10.0 The Pay is 400.00 Enter number of hours and rate 00.0 15.0 The Pay is 0.00 Enter number of hours and rate 60.0 15.0 The Pay is 1050.00 Enter number of hours and rate 70.0 15.0 The Pay is 1350.00 Enter number of hours and rate -1.0 0.0 Errors in Hours Note for ‘ and ’ SOLUTIONS BY FRIENDS