// Begin Psuedocode Design // Author: Liam Smith // Date: 02/03/06 // Version: Assignment 2 Pseudocode Design // Lecturer: Digby Barrett & Kim Ng // Objective: Read in fuel consumtion figures for various cars in litres // per 100 Kilometres until a negetive value is input. // The fuel consumption figures will be floating-point // data. The negetive value is a SENTINEL value and is // NOT to be processed. // // Print out the number of cars with: // good consumption (less than 7) // fair consumption (7 to 10) // poor consumption (over 10) while cons = more0 write("Enter fuel consumption") read(cons) if(cons = 0 to 7) good+1 end if else if(cons = 7 to 10) fair+1 end if else if(temp = more 10) poor+1 end if else if(temp = less 0) poor+1 end if end while total=total+good+fair+poor+inval write("Good consumption = [good]") write("Fair consumtion = [fair]") write("Poor consumption = [poor]") write("Invalid entries = [inval]") write("Total = [total]") // End Psuedocode Design // Begin Trace Table // Author: Liam Smith // Date: 02/03/06 // Version: Assignment 2 Trace Table // Lecturer: Digby Barrett & Kim Ng // Objective: Read in fuel consumtion figures for various cars in litres // per 100 Kilometres until a negetive value is input. // The fuel consumption figures will be floating-point // data. The negetive value is a SENTINEL value and is // NOT to be processed. // // Print out the number of cars with: // good consumption (less than 7) // fair consumption (7 to 10) // poor consumption (over 10) Input | while>0 | if>0&<7 | if>7&<10 | if>10 | Output ---------|-----------|-----------|------------|---------|----------- 6.3 | True | True | False | False | Cons=Good | | | | | 10.0 | True | False | True | False | Cons=Fair | | | | | 7.0 | True | False | True | False | Cons=Fair | | | | | 7.1 | True | False | True | False | Cons=Fair | | | | | 8.6 | True | False | True | False | Cons=Fair | | | | | 12.3 | True | False | False | True | Cons=Poor | | | | | 11.2 | True | False | False | True | Cons=Poor | | | | | 6.4 | True | True | False | False | Cons=Good | | | | | -8.0 | False | False | False | False | ------ // End Trace Table // Begin CPP Code // Author: Liam Smith // Date: 02/03/06 // Version: 1.0 // Lecturer: Digby Barrett & Kim Ng // Objective: Read in fuel consumtion figures for various cars in litres // per 100 Kilometres until a negetive value is input. // The fuel consumption figures will be floating-point // data. The negetive value is a SENTINEL value and is // NOT to be processed. // // Print out the number of cars with: // good consumption (less than 7) // fair consumption (7 to 10) // poor consumption (over 10) #include int main() { // Identifiers and their values. float cons=0; int good=0, fair=0, poor=0, inval=0, total=0; // While loop will loop until an value less than 0 is entered. while (cons>=0) { // "cout" display's a promt or a message, "cin" allows the user to input data. cout<<"\n Enter fuel consumption in litres per 100km:"; cin>>cons; // "if" gives a condition, if the condition is true an action is performed, if // the condition is false the next condition is tested. if (cons>=0 && cons<7) good++; // "else" tests the next "if" condition, only if the previous "if" was false. else if (cons>=7 && cons<=10) fair++; else if (cons>10) poor++; else if (cons<0) inval++; } // Total is equal to "good, fair and poor" consumption and invalid entries // added together. total=total+poor+fair+good+inval; cout<<"\n -----------------------------"; cout<<"\n Good Fuel Consumption ="<