Complete the trace table using the program in Figure 2.
Figure 2
public static int calculatePrice(int weight, int distance, int expressFee) {
if (expressFee == 0)
{
return weight * distance;
} else
{
return (weight * distance) + expressFee;
}
}
public static void Main() {
int numOne, numTwo, numThree, cost;
Console.Write("Enter weight: ");
numOne = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter distance: ");
numTwo = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter express fee, 0 for none: ");
numThree = Convert.ToInt32(Console.ReadLine());
cost = calculatePrice(numOne, numTwo, numThree);
if (numThree == 0)
{
Console.WriteLine($"Standard: {cost}");
} else
{
Console.WriteLine($"Express: {cost}");
}
}
| numOne | numTwo | numThree | Final output |
|---|---|---|---|
| 4 | 15 | 0 | |
| 6 | 10 | 25 | |
| 3 | 8 | 12 |
208 exam-style questions on AQA GCSE Computer Science Representing algorithms. Each one has a worked solution and a mark scheme showing where the marks go.