An electricity supply company calculates the customer monthly bill amounts. Draw a Flow chart and a Pascal Program to input the bill amounts of 10 electricity bills and output total amount of all the electricity bills.
program SumBillAmount; var C,Tot,BillAmt:integer; begin C:=1; Tot:=0; while (c <=10) do begin write('Enter a Bill Amount?'); readln(BillAmt); Tot:=Tot+BillAmt; C:=C+1; end; write('Total Bill Amount of all the bill is ='); writeln(Tot); readln; end.
A Company calculates the bonus for each employee. Write a Pascal Program to input an Employee number, Sex and Basic Salary and output the Total Salary with Bonus amount of the Employee. (Male gets Bonus 5000 and Female gets Bonus 3000)
program SumBillAmount; var EmpNo:String; Sex:char; Bonus:integer; Basic, Total:real; begin write('Enter a Empoyee No?'); readln(Empno); write('Enter Sex ?'); readln(Sex); write('Enter Basic Salary'); readln(Basic); if (Sex='M') then Bonus:=5000 else Bonus:=3000; Total:=Basic+Bonus; write('Total Salary='); writeln(Total:8:2); readln; end.
Write a Pascal program to Input marks of 50 students into to an array and output the number of students whose mark is greater than the class average mark.
program PrintmorethanAVG; const NoStudents=50; type marks = array [ 1..NoStudents] of integer; var x,StCount:integer; StAvg,StTot:real; Stmarks:marks; begin x:=1; StTot:=0; StAvg:=0; StCount:=0; while (x<=NoStudents) do begin writeln('Enter a marks?'); read(Stmarks[x]); StTot:=StTot+Stmarks[x]; x:=x+1; end; StAvg:=Sttot/NoStudents; x:=1; while (x<=NoStudents) do begin if Stmarks[x]>StAvg then begin StCount:=StCount+1; end; x:=x+1; end; write('Number of Students Got More than Average :'); writeln(StCount); readln; readln; end.
Write a Pascal program to Bubble Sort an array
PROGRAM BubleSort(input, output); CONST MaxElts = 5; TYPE IntArrType = ARRAY [1..MaxElts] OF Integer; VAR arr: IntArrType; PROCEDURE ReadArr(VAR a: IntArrType); VAR x:integer; BEGIN x := 1; WHILE x<=MaxElts DO BEGIN readln(a[x]); x := x + 1 END; END; {procedure to swap data} PROCEDURE swap(VAR a: Integer; VAR b: integer); VAR temp:integer; BEGIN temp:=a; a:=b; b:=temp; END; {Procedure to bubble sort not an efficient algorithm} PROCEDURE Bsort(VAR arr: IntArrType); VAR i, j : integer; BEGIN FOR i := 1 TO MaxElts DO FOR j := 1 TO MaxElts-1 DO IF arr[j] > arr[j + 1] THEN BEGIN swap(arr[j],arr[j + 1]); END; END; {procedure to bubble sort an efficient algorithm} PROCEDURE BsortEfficient(VAR arr: IntArrType); var lastswap,i,endloop:integer; swapdone:boolean; BEGIN endloop:=MaxElts; swapdone:=False; while not swapdone do begin i:=1; swapdone:=True; while i<endloop do begin IF arr[i] > arr[i + 1] THEN BEGIN swap(arr[i],arr[i + 1]); lastswap:= i; swapdone:=False; END; i:=i+1; end; endloop:=lastswap end; end; {Procedure to print elements of an array} PROCEDURE ArrPrint(VAR arr: IntArrType); VAR I:integer; BEGIN FOR i := 1 TO MaxElts DO writeln(arr[i]) ; END; {main Program} BEGIN ReadArr(arr); Bsort(arr); ArrPrint(arr); readln; END.
A student file which is stored in the storage consist of Student Number, Name and Marks. Write a Pascal to below given tasks.
a) Write a procedure to input 20 Records of Students.b) Write a Procedure to input a record No and Display the Record.
c) Write a procedure to Display all the records.
Const StNum=20; Type Str25 = String[25]; StRec = Record Stno, Stname : Str25; StMarks : integer; End; mf = File of StRec; Var MarksArray : Array[1..StNum] of StRec; MarksFile : mf; i : 1..StNum; {procedure to input a record} Procedure EnterNewMark(var newStMark : StRec) ; Begin Writeln('Please enter the Student Marks Details: '); Write('Student No: '); Readln(newStMark.Stno); Write('Student Name: '); Readln(newStMark.Stname); Write('Student Marks : '); Readln(newStMark.StMarks); End; {procedure to display a record} Procedure ListNewMark(var m :mf;i :integer); var tempStRec : StRec; Begin ReSet(m); Seek(m, i-1); Read(m, tempStRec); Close(m); Writeln('The Student record details #',i,':'); Writeln; Writeln('Student No: ', tempStRec.Stno); Writeln('Student Name: ', tempStRec.Stname); Writeln('Student Marks: ', tempStRec.Stmarks); end; {procedure to display all the record} Procedure ListAllMark(var m :mf); var tempStRec : StRec; Begin ReSet(m); Seek(m, 0); while not eof(m) do begin Read(m, tempStRec); Writeln('Student No: ', tempStRec.Stno); Write(chr(9)); {tab} Write('Student Name: ', tempStRec.Stname); Write(chr(9)); Write('Student Marks: ', tempStRec.Stmarks); end; end; {Main Program} Begin Assign(MarksFile, 'bookrec.dat'); ReWrite(MarksFile); For i := 1 to StNum do Begin EnterNewMark(MarksArray[i]); { bookRecArray[i] now contains the book details } Write(MarksFile, MarksArray[i]); End; Close(MarksFile); Writeln('Record Successfully saved in a file!'); Write('Enter a record Number to display '); Readln(i); ListNewMark(MarksFile,i); Writeln('List All Records.......'); ListAllMark(MarksFile); Readln; End.
No comments:
Post a Comment