A-level Computing/AQA/Paper 1/Skeleton program/AS2017

This is the skeleton code for the AQA AS Paper from 2017. This code is useful for those retaking, and can also be used as a practise for those taking a newer paper.

This is where suggestions can be made about what some of the questions might be, and how they can be solved in different programming languages. If you see that a solution to a question is missing in a language you use, be bold and add it!

Please be respectful and do not vandalise or tamper with the page, as this would affect students' preparation for their exams!

Python Solution
ALTERNATIVE

def SaveFile(Field): fileName = input('Enter desired file name: ') fileWrite = open(fileName,'w') count = 0 for Row in range(FIELDLENGTH): for Column in range(FIELDWIDTH): fileWrite.write(str(Field[Row][Column])) fileWrite.write('| ' + str(count) + '\n') count += 1 fileWrite.close

def Simulation: YearsToRun = GetHowLongToRun if YearsToRun != 0: Field = InitialiseField if YearsToRun >= 1: for Year in range(1, YearsToRun + 1): SimulateOneYear(Field, Year) else: Continuing = True Year = 0 while Continuing: Year += 1 SimulateOneYear(Field, Year) Response = input('Press Enter to run simulation for another Year, Input X to stop: ') if Response == 'x' or Response == 'X': Continuing = False writeChoice = input('Do you want to save the file (Y/N): ')#NEW if writeChoice == 'Y':#NEW SaveFile(Field)#NEW print('End of Simulation') input
 * 1) edited simulation

Delphi/Pascal Solution
Answer :

Java Solution
Answer :call method in simulationstatic void WriteFile(char[][] Field) { try { AQAWriteTextFile2017 FileHandle = new AQAWriteTextFile2017("test.txt"); for (int Row = 0; Row < FIELDLENGTH; Row++) { for (int Column = 0; Column < FIELDWIDTH; Column++) { String val = Character.toString(Field[Row][Column]); FileHandle.writeToTextFile(val, ""); }           FileHandle.writeToTextFile(" "); }           FileHandle.closeFile; }   catch(Exception e)    { CreateNewField(Field); }   }

Java Solution 2
Answer :call method in simulation

C# Solution
Answer :

C# Solution 2 - the better one *if you don't want to load file again*
Answer :

Python Solution:
Answer :

Adding Rocks to the Simulation
Currently the rocks are defined as a constant but not used - we can either allow the user to enter a number of rocks to be randomly placed, or add a random number of rocks to the field.

Changing the seed position
This includes either allowing the player to set exact coordinates of the seed (which should also implement column letters), or spawn the seed in a random position.

C# Solution
Answer :

Answer 2 :

VB.Net Solution
Within, below the code that selects the number of rocks if that is in use.

Adding a new function:

Python Solution
This solution will require that you add  to the start of the program.

Change the program so when you enter number of years it doesn't accept any character input and returns an error with another chance of input.
Change the program so when you enter number of years it doesn't accept any character input and returns an error with another chance of input.

C# Solution
Answer :

Delphi/Pascal Solution
Answer :

Java Solution
Answer :

Python Solution
Answer :

VB.NET Solution
Answer :

Add functionality for plants that thrive on or require frost
Add functionality for plants that thrive on or require frost

C# Solution: Adds very frosty plants
Answer :

C# Solution: Adds frosty plants
Answer :

Delphi/Pascal Solution
Answer :

Java Solution
Answer :

Python Solution
Answer :

VB.NET Solution
Answer :

Intelligent File Opening
When the program loads a file, if the user does not include the ".txt" extension, ensure that it is automagically added.

C# Solution
Answer :

Delphi/Pascal Solution
Answer :

Java Solution
Answer :

Python Solution
Answer :

VB.NET Solution
Answer :

C# Solution
Answer :

C# Solution 2 (an easier on that requires less work and looks cooler!)
Answer :

static void Display(char[,] Field, string Season, int Year) {           Console.WriteLine("Season: " + Season + " Year number: " + Year); String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHI";

for (int column = 0; column < FIELDWIDTH; column++) {               Console.Write(alphabet[column]); }           Console.WriteLine; for (int Row = 0; Row < FIELDLENGTH; Row++) {               for (int Column = 0; Column < FIELDWIDTH; Column++) {                   Console.Write(Field[Row, Column]); }               Console.WriteLine("| " + String.Format("{0,3}", Row)); }       }

C# Solution 3 (Solution 1 but uses vertical numbers instead of base 62 *works for field sizes larger than 62)
Answer :

Pascal Solution
Answer :

Java Solution
Answer :

Python Solution
Answer 1: Answer 2: Answer 3: Answer 4: Vertical Columns Answer 5: Answer 6:

C# Solution
Answer :

const char BIRD = 'B'; // Addition of 'Bird

static void SimulateWinter(char[,] Field) {           for (int Row = 0; Row < FIELDLENGTH; Row++) {               for (int Column = 0; Column < FIELDWIDTH; Column++) {                   if (Field[Row, Column] == PLANT) {                       Field[Row, Column] = SOIL; }               }            }            Random rnd = new Random; // Random variable 'rnd' int BirdFlight = rnd.Next(0, FIELDWIDTH); for (int Row = 0; Row < FIELDLENGTH; Row++) //Random Column Selected between 0 and FIELDLENGTH {               if (Field[Row, BirdFlight] == SEED) // Change SEED to BIRD {                   Field[Row, BirdFlight] = BIRD; }           }        }

static void SimulateOneYear(char[,] Field, int Year) {           SimulateSpring(Field); Display(Field, "spring", Year); SimulateSummer(Field); Display(Field, "summer", Year); SimulateAutumn(Field); Display(Field, "autumn", Year); SimulateWinter(Field); Display(Field, "winter", Year); Console.WriteLine("A bird has flown down a column! All seeds in this column have been eaten!!"); //Adds a Message }

static void SimulateSpring(char[,] Field) {           int PlantCount = 0; bool Frost = false; for (int Row = 0; Row < FIELDLENGTH; Row++) {               for (int Column = 0; Column < FIELDWIDTH; Column++) {                   if (Field[Row, Column] == BIRD) // Changes any 'Bird' characters (B) to Soil. {                       Field[Row, Column] = SOIL; }                   if (Field[Row, Column] == SEED) {                       Field[Row, Column] = PLANT; }               }            }

Pascal Solution
Answer :

Java Solution
Answer : static void SimulateBird(char[][] Field) {   Random RandomInt = new Random; int PlantCount = 0; boolean Bird=false;

Python Solution
Answer :

VB.NET Solution
Answer : Function SimulateWinter(ByVal Field As Char) As Char Dim bcolumn As Integer For Row = 0 To FIELDLENGTH - 1 For Column = 0 To FIELDWIDTH - 1 If Field(Row, Column) = PLANT Then Field(Row, Column) = SOIL End If           Next Next bcolumn = Rnd * 34 For row = 0 To 19 If Field(row, bcolumn) = SEED Then Field(row, bcolumn) = SOIL End If       Next Return Field End Function 'Big up Newvic mandem u get me 'The Real Swifty $IBRAHIM$ THE ROADMAN69

Answer 2: Function SimulateWinter(ByVal Field As Char) As Char Dim AvianFeast As Integer = CInt(Math.Floor((FIELDWIDTH + 1) * Rnd)) Console.WriteLine("The birds are eating all the seeds in column " + CStr(AvianFeast + 1) + "!") For Row = 0 To FIELDLENGTH - 1 For Column = 0 To FIELDWIDTH - 1 If Field(Row, Column) = PLANT Then Field(Row, Column) = SOIL End If               If Field(Row, Column) = SEED And Column = AvianFeast Then Field(Row, Column) = SOIL End If           Next Next

Return Field End Function 'Like Chilli Memes on Facebook 'by THE BIG POKESIE - discord pokesie#2884 add me <3

C# Solution
Answer :

Java Solution
Answer:

Python Solution
Answer :

Another Answer :

C# Solution
Answer :

Pascal Solution
Answer :

Java Solution
Answer :

Python Solution
Answer 1: Answer :

VB.NET Solution
Answer : 'to start the tornado Function SimulateSummer(ByVal Field As Char) As Char Dim RainFall, tornado As Integer Dim PlantCount As Integer RainFall = Int(Rnd * 3) tornado = Int(Rnd * 10) If tornado = 1 Then Console.WriteLine("A tornado occurs") Tornadoo(Field) End If       If RainFall = 0 Then PlantCount = 0 For Row = 0 To FIELDLENGTH - 1 For Column = 0 To FIELDWIDTH - 1 If Field(Row, Column) = PLANT Then PlantCount += 1 If PlantCount Mod 2 = 0 Then Field(Row, Column) = SOIL End If                   End If                Next Next Console.WriteLine("There has been a severe drought") CountPlants(Field) End If       Return Field End Function 'how the tornado works Sub Tornadoo(ByRef Field As Char) Dim column, row, plants, rock, prow, pcolumn, srow, scolumn As Integer column = Int(Rnd * 24 + 5) row = Int(Rnd * 10 + 5) For count = row - 5 To row + 5 For count2 = column - 5 To column + 5 If Field(count, count2) = PLANT Then Field(count, count2) = SOIL ElseIf Field(count, count2) = SEED Then plants = plants + 1 Field(count, count2) = SOIL ElseIf Field(count, count2) = ROCKS Then rock = rock + 1 Field(count, count2) = SOIL End If           Next Next For count = 0 To plants prow = Rnd * 10 + (row - 5) pcolumn = Rnd * 10 + (column - 5) Field(prow, pcolumn) = SEED Next For count = 0 To pcolumn srow = Rnd * 10 + (row - 5) scolumn = Rnd * 10 + (column - 5) Field(srow, scolumn) = ROCKS Next End Sub ~ 'Big up NewVic man dem 'The Real Swifty ~

Python Solution
Answer 1:

Python Solution
Answer 2:

Python Solution
Answer 3:

Python Solution
Answer 4:

Java Solution
Answer:

C# Solution
Answer 1:

Answer 2:

VB.Net Solution
Answer 1:

Implement Season 0, i.e. show the state of the field when the seed is sown - at the start of Spring
[i.e. When the simulation starts, the first field shown is the state of the field at the END of Spring. If you start, for example, with the TestCase.txt file, you will not see the field as it is in the TestCase.txt file, but only once Spring has sprung. This amendment requires the simulation to show the point when Spring starts and then continues as before. Thus, any test file used as the starting point will be shown as Season 0 (to confirm that the field state is as it should be when the test file is read, and the simulation then continues. Hope this is a clearer explanation.  Apologies if this has simply muddied the water.]

I've read this at least 40 times and I still have no idea what this question means.

I think this will come up - Excellent question.

ARA

VB.NET Solution
Answer :

Java Solution
Answer:

C# Solution
Answer :

Python Solution
Answer :