Beruflich Dokumente
Kultur Dokumente
CP-AS-10-08
COMP1
Answer all questions Marks 25
Page 1 of 9
Mark scheme
Put your answers onto the document "CP-AS-10-08 Answers"
CP-AS-10-08
This program when finished will enable a user to carry out some useful everyday conversions. Along with the answer document you will find the skeleton code for this program on the school website Exmouth College > Subjects > ICT & Computing > ICT Year 12 :.
namespace CSharpExamPractice1 { class Program { static int selection; static int MenuOption() { int choice = 0; bool validNumber = false; Console.WriteLine(); Console.WriteLine("Enter a number to choose an option: "); Console.WriteLine(" 1 Convert Fahrenheit to Celsius 3 Convert Miles to Kilometers"); Console.WriteLine(" 2 Convert to Fahrenheit 4 Convert Kilometers to Miles"); Console.WriteLine(" 5 Exit"); Console.WriteLine(); Console.Write("Your choice: "); choice = Convert.ToInt32(Console.ReadLine()); return choice; } static bool ValidateData(string s) { string str = s; try // we haven't covered validation yet but you will find the details on pages 95 - 98 { double d = Convert.ToDouble(s); return true; } catch { Console.WriteLine("This was not a number"); Console.WriteLine("Please try again"); return false; }
Page 2 of 9
Mark scheme
}
CP-AS-10-08
static void ConvertToCelsius() { String DegreesFahrenheitStr; double DegreesFahrenheit; double DegreesCelsius; Console.Write("Enter fahrenheit value : "); DegreesFahrenheitStr = Console.ReadLine(); DegreesFahrenheit = Convert.ToDouble(DegreesFahrenheitStr); DegreesCelsius = (DegreesFahrenheit - 32)*(5/9); Console.Write("This is "); Console.WriteLine(DegreesCelsius); } static void ConvertToFahrenheit() { Console.WriteLine("You will need to write the code for the procedure ConvertToFahrenheit yourself"); } static void ConvertToKilometers() { Console.WriteLine("You will need to write the code for the procedure ConvertToKilometers yourself"); } static void ConvertToMiles() { Console.WriteLine("You will need to write the code for the procedure ConvertToMiles yourself"); } static void Main(string[] args) { Console.WriteLine("Useful Converter"); selection = MenuOption(); while (selection != 5) { switch (selection) { case 1: ConvertToCelsius(); break; //the break statement the case body case 2: ConvertToFahrenheit(); break; //the break statement the case body case 3: ConvertToKilometers(); break; //the break statement the case body case 4: ConvertToMiles(); break; //the break statement the case body
transfers control
out ot
transfers control
out ot
transfers control
out ot
transfers control
out ot
Page 3 of 9
Mark scheme
} selection = MenuOption(); } if (selection < 5) Console.ReadLine(); } } }
CP-AS-10-08
(1 Mark)
(1 Mark)
(1 Mark)
(1 Mark)
Page 4 of 9
Mark scheme
CP-AS-10-08
Write a procedure ConvertToKm to convert miles to kilometers. The conversion formula is: 1 mile = 1.6 km
declare variables MilesStr string Kilometers & Miles double = all three 1 mark correct type 1 mark Good prompt and input string = 1 mark Convert string to double = 1 mark correct assignment to calclate = 1 mark correct output 1 mark MAX 5
(5 Marks)
An example of boundary data might be the empty string. This should not cause an error but give the empty string as a result. Write the instructions necessary to handle this boundary value. Copy the entire code for your ConvertToKm procedure into your answer.
(4 Marks)
ConvertToKm.
To test a routine adequately, normal, boundary and erroneous data need to be used. Look at your version of the function ConvertToKm. Give two suitable values of normal test data.
try / catch 1 mark If length = 0 1 mark output "" 1 mark
(2 Marks)
Page 5 of 9
Mark scheme
CP-AS-10-08
This question refers to the main MenuOption sub-program. The sub program should show the menu repeatedly to the user until the user enters a valid number (1,2,3,4 or 5). Write the code to repeat the input to the variable choice until a correct value is entered.
If (Choice <1) OR (Choice >5) 1 mark for Approriate error message 1 mark If(choice >1) AND (choice<6) then drop out of loop 1 mark Loop back if not 1 mark
(4 Marks)
Take a copy of the output screen when you run your program using these values.
Examples of values in screen
(2 Marks)
(2 Marks)
Take a copy of the output screen when you run your program using these values.
Evidence of correct input 2 marks
(2 Marks)
Computing New 2008 COMP1 Q 1
25
Page 6 of 9
Mark scheme
CP-AS-10-08
COMP2
Answer all questions Marks 8
Look at the truth table below. +-------+-------+-------+ | Input | Input | Output| | A | B | Q | +-------+-------+-------+ | 0 | 0 | 1 | +-------+-------+-------+ | 0 | 1 | 0 | +-------+-------+-------+ | 1 | 0 | 0 | +-------+-------+-------+ | 1 | 1 | 0 | +-------+-------+-------+ What logic gate does this represent?
NOR Gate
(1 Mark)
Page 7 of 9
Mark scheme
CP-AS-10-08
An interior light in a two-door car is controlled by two switched that the drive can turn on or off and two sensors, one per door. The switches are named A and B. The door sensors are named C and D. The interior light is named L. If a door is open the output of its sensor is on. If a door is closed the output of its sensor id off. Of both switches A and B are off then the light L is always off. If switch A is on the light L is always on. If switch B is on and switch A is off then: the light L turns on if one or more of the car doors is opened. The light L turns off if both of the doors are closed. The following symbols are used to represent logic gates: O-
AND OR NOT Using only AND, OR and NOT gates draw a cicuit for this system in the box below. You may not need to use all three types aof gate. +---------------------------------------------------+ | | | | A-O | | | | | | | | | | | B-O | | | | | | O-L | | | | C-O | | | | | | | | | | | D-O | | | | | | | +---------------------------------------------------+
Page 8 of 9
Mark scheme
CP-AS-10-08
(3 Marks)
Write a Boolean expression to represent the logic of the interior light system
A + B . (C + D) A + B . C + B . D _ A + A . B . (C + D) _ _ A + A . B . C + A . B . D
(1 Mark)
(3 Marks)
Computing Summer 2009 COMP2 Q 4
Page 9 of 9