Friday, 31 January 2014

CSC 202 PAST QUESTION FOR 2011/2012 SOLVED IN PYTHON PROGRAMMING LANGUAGE

QUESTION 1B

Write a program that computes the numbers of accumulated AIDS cases A(t) in the Nigeria in year t according to the formula
                A(t) = 174.6(t – 1981.2)

SOLUTION IN PYTHON LANGUAGE

>>> t = input("enter year t :")
>>> A = 174.6 * (( t - 1981.2)**3)
>>> print A


QUESTION 1C

Write a program to compute compound interest on an initial balance over a number of years. Run it for a period of about 10yrs and see if you can follow how it works

SOLUTION IN PYTHON LANGUAGE

>>> t = input("enter years :")
>>> r = input("enter rate: ")
>>> p = input("enter initial balance amount :")
>>> for i in range(1 ,t+1):
     A = p * ((1 + r )**t)
     p = A
>>> print A


QUESTION 2A

Suppose that the final course mark of students attending a university course is calculated as follows. Two examination papers are written at the end of the course. The final mark is either the average of the two papers or the average of the two papers and the class record mark (all weighted equally), whichever is the higher. Write a program to compute and prints each students mark, with the comment PASS or FAIL (50% being the pass mark).

SOLUTION IN PYTHON LANGUAGE

>>> scoreOne = input("enter score for paper one")
>>> scoreTwo = input("enter score for paper two: ")
>>> classScore = input("enter class record mark: ")
>>> averageScore = (scoreOne + scoreTwo) / 2
>>> if (classScore > averageScore):
     if ( classScore >= 50):
           print "PASS"
     else:
           print "FAIL"
elif(averageScore > classScore):
     if(averageScore >=50):
           print "PASS"
     else:
           print "FAIL"
elif (averageScore == classScore):
     if(averageScore >=50):
           print "PASS"
     else:
           print "FAIL"


QUESTION 2B

Write a fortran 90 program to calculate an hourly employee’s weekly pay

SOLUTION IN PYTHON LANGUAGE

>>> hoursWorked = input("how many hours worked :")
>>> hoursWorked_perDay = input("how many hours worked per day: ")
>>> nosOfDays_perWeek = input("enter nos of days worked per week :")
>>> weeklyPay = input("enter amount pay weekly :")
>>> total_hours = hoursWorked_perDay * nosOfDays_perWeek
>>> hourlyPay = weeklyPay / total_hours
>>> print hourlyPay


QUESTION 2C

Write a fortran 90 program to calculate the hypotenuse of a triangle from the two sides

SOLUTION IN PYTHON LANGUAGE

import math
>>> sideA = input("input side A for the triangle :")
>>> sideB = input("input side B for the triangle :")
>>> sideC = math.sqrt ((sideA**2) + (sideB)**2)
>>> print sideC


QUESTION 3A

A class of students write a test and each student name (max of 15characters) and mark is entered in a data file. Assume there are no negative marks. Write a program which prints out the name of the students with the highest mark, together with his or her mark. Assuming that there is only one highest mark. A first level structured plan could be
-          Start
-          Find top student and top mark
-          Print top student and top mark
Step 2 needs elaborating, so a more detail plan might be:
-          Start
-          Initialize top mark(to get process going)
-          Repeat for all students
-          Read name and mark
-          If mark > topmark then
Replace topMark with mark
Replace topName with name
-          Print topName and topMark
-          Stop

SOLUTION IN PYTHON LANGUAGE

>>> datafile = open("myFile2.txt","r")
>>> text = datafile.readline() 
>>> listOfScore = []
>>> for  s  in  text:
     score = s.split(" ")
     listOfScore.append ( score[0])

>>> highest = listOfScore[0]
>>> for k in range(1,len(listOfScore)):
     if( highest < listOfScore[k] ):
           highest = listOfScore[k]
           index = k
>>> print text[index]


QUESTION 3C

Write a fortran program which computes n!

SOLUTION IN PYTHON LANGUAGE

>>> n = input("enter n value to be computed")
>>> i = 1
>>> for  k  in  range(1,n+1):
      i *= k   

>>> print i

No comments:

Post a Comment