Question Constellation Sign up for free

AQA · GCSE · Computer Science · Higher

Constructing a string stock code

Q07.0 4 marks

A shop owner wants to create stock codes for each type of sweet they sell. Figure 5 shows some of the sweets.

Figure 5
sweetIDsweetNamebrand
S1WINE GUMSMAYNARDS
S2COLA CUBESBERRYMANS
S3STARBURSTWRIGLEY
  • A stock code is made up of the sweetID.
  • It then uses the first letter and the second letter in sweetName.
  • It then uses the first letter of the brand.

For example, the stock code for WINE GUMS would be S1WIM, and the stock code for STARBURST would be S3STW.

Write a C# program to create the stock code for a sweet. The program should get the user to enter the sweetID, sweetName and brand; create the stock code; and assign the stock code to a variable called code. Use meaningful variable name(s) and C# syntax.

Write your answer first. You can study the marking guidance whenever you need it.

Study the marking See what earns credit and compare it with a full-mark answer.

Marking points

  1. 1 Uses concatenation to construct the stock code.
  2. 2 Reads sweetID, sweetName and brand correctly.
  3. 3 Uses the whole sweetID, sweetName indexes 0 and 1, and brand index 0.
  4. 4 Assigns the constructed value to the variable code.

Full-mark answer

string sweetID = Console.ReadLine(); string sweetName = Console.ReadLine(); string brand = Console.ReadLine(); string code = sweetID + sweetName[0] + sweetName[1] + brand[0];

Why this answer loses marks

I read all three values and concatenated the complete strings.

The stock code needs the specified character positions rather than every character from each source string.