Sei sulla pagina 1di 8

Assignment/Project name Problem Solving Strategies for Algorithm

By: Lisa Forbes

An assignment submitted in partial fulfillment of the requirements for the course Fundamentals of Algorithm Instructor: Mr. Rohan Simpson Date: June day, 2013

Department of Communication and Information Technology Bethlehem Moravian College

Question 1 START READ cus_name, pur_amt, taxcode tax_exmpt = 0 state_sales_tax = 0.03 federal_state_sales_tax = 0.05 special_tax = 0.07 IF taxcode = = 0 THEN print tax exempt tax_exempt tax=pur_amt*tax_exempt total_amount=pur_amt+tax PRINT customer name, purchase amount, total amount cus_name, pur_amt, total_amount ELSE IF taxcode == 1 THEN tax = pur_amt * state_sales_tax Total amount = pur_amt + tax PRINT customer name, purchase amount, total amount cus_name, pur_amt, total_amount ELSE IF taxcode = =2 THEN tax = pur_amt * federal_state_sales tax total_amount = pur_amt + tax PRINT customer name, purchase amount, total amount cus_name, pur_amt, total_amount ELSE IF taxcode = =3 THEN tax = pur_amt * special_tax total_amount = pur_amt + tax PRINT customer name, purchase amount, total amount cus_name, pur_amt, total_amount ENDIF STOP

TRACE TABLE cus_name Ron Arnold Maxine Jones Chantal Butler Shadane Butler

purchase_name 10 000 11 000 12 000 14 000

taxcode 0% 1% 2% 3%

sales tax 0 110 240 420

total-amount 10 000 11 1110 12 240 14 420

Question 2 START READ Name READ Exam_score count = 0 sum = 0 WHILE exam_score <> 999 DO IF exam_score > = 0 && exam_score <= 100 THEN count = count + 1 sum = sum + score ENDIF READ Name READ exam_score ENDWHILE avg=sum/count PRINT name, name PRINT exam score, exam_score PRINT average avg STOP Name Chantal Butler Shadane Butler Ron Arnold Lee Grant ExamScore 80 95 40 999 Count 1 2 3 4 TotalScore 80 175 350 Average

Question 3 START READ Fname READ Lname READ Idum READ cw_gd READ exam_gd WHILE cw_gd <> -1000 DO total_gd=cw_gd+exam_gd IF total_gd>80 THEN PRINT first name, last name, Id number, course work grade, exam grade, total grade Fname, Lname, Idnum, cw_gd, exam_gd, total_gd ENDIF READ Fname READ Lname READ Idum READ cw_gd READ exam_gd ENDWHILE STOP cw_grade 50 45 49 -1000 Fname Chantal Shadane Ron Lname Butler Butler Arnold Idnum 1 2 3 exam_gra de 40 45 40 Totalgrad e 90 90 89

Question 4 START READ Pat_fir_nm count = 0 WHILE Pat_fir_nam <> usain DO count = count + 1 READ Pat_fir_nm ENDWHILE PRINT You can only accept one Usain PRINT number of patient first name , count STOP

PatientFirstName Ron Chantal Shadane Usain

Count 1 2 3 3

Output

We can only accept one Usain

Question 5 START READ Name FOR Counter = 1 to 20 DO IF Name = Asafa Powell THEN PRINT Bingo you have guessed right ELSE PRINT Im sorry please try again ENDIF READ name ENDFOR STOP

Name Shadane Chantal Ron Asafa Powell

Counter 1 2 3 4

Output Im sorry please try again Im sorry please try again Im sorry please try again Bingo, You guessed right

Question 6 START READ Age WHILE age <> 999 DO age_month = age *12 IF age_ month > 300 THEN PRINT * * * * , age_month ENDIF READ age ENDWHILE STOP

Age 20 50 35 40

Months 240 600 420 480

Output **** 600 **** 420 **** 480

The Department of Communication and Information Technology

Certification of Authorship of work

Submitted to: Mr. Rohan Simpson Students Name: Date of Submission: Purpose and Title of Submission:

Certification of Authorship: I hereby certify that I am the author of this document and that any assistance I received in its preparation is fully acknowledged and disclosed in the document. I have also cited all sources from which I obtained data, ideas, or words that are copied directly or paraphrased in the document. Sources are properly credited according to accepted standards for professional publications. I also certify that this paper was prepared by me for this purpose. Student's Signature:________________________________________________________

Potrebbero piacerti anche