The Student Room Group

COMP1 + COMP2 June 2013 - How did you find it? Any tips

Scroll to see replies

Reply 20
Original post by MissMyDawgs
Got a quick question, just want to clarify. What exactly does Dim as 'String' and 'Single' mean. I know what Dim is but I can't seem to see the difference between string and single because when I use either it still works


Strings are designed to store what you might think of as text, Singles are designed to store numbers (more specifically a low precision floating point number, you'll learn about floating point at A2, but for now at AS Level you can just assume that they store low precision decimals)

Ultimately, you can choose to store numbers as strings but it's not a good idea if you need to perform calculations on them. If you had two string variables var1 and var2, both equal to 1, and then tried to output var1+var2, your result would be 11 rather than 2, because as far as the compiler is concerned, you're just concatenating (joining) two strings together, not adding numbers.

Singles are designed for those low precision floating point numbers, (again, think of them as low precision decimals for now). You can perform calculations on them as they are designed for this purpose. These are only ever going to be approximations of real numbers though, if you need a slightly better approximation then you want a Double. If you want a really high level of precision then the Decimal datatype would be more appropriate. You could still use a Decimal to store something which doesn't need a high level of precision (like a whole number) but this would be wasting space in memory. For a whole number you'd be much better off with the Integer datatype.
Original post by Jarred
Strings are designed to store what you might think of as text, Singles are designed to store numbers (more specifically a low precision floating point number, you'll learn about floating point at A2, but for now at AS Level you can just assume that they store low precision decimals)

Ultimately, you can choose to store numbers as strings but it's not a good idea if you need to perform calculations on them. If you had two string variables var1 and var2, both equal to 1, and then tried to output var1+var2, your result would be 11 rather than 2, because as far as the compiler is concerned, you're just concatenating (joining) two strings together, not adding numbers.

Singles are designed for those low precision floating point numbers, (again, think of them as low precision decimals for now). You can perform calculations on them as they are designed for this purpose. These are only ever going to be approximations of real numbers though, if you need a slightly better approximation then you want a Double. If you want a really high level of precision then the Decimal datatype would be more appropriate. You could still use a Decimal to store something which doesn't need a high level of precision (like a whole number) but this would be wasting space in memory. For a whole number you'd be much better off with the Integer datatype.

Oh thanks : ) I've found something else I'm stuck on. I got the answer off my friend but I want to know what is actually going on cos I'm kind of confused.

Question: The user enters an amount of money as a whole number. The program should calculate and display how many £20, £10 and £5 notes and £2 and £1 coins are needed to make up this amount of money. For example, £37 would give 1 x £20, 1 x £10, 1 x £5 and 1 x £. Hint use integer division and modulo operation

Ermm sorry, I know I'm sounding stupid but what is the modulo operation?

Also the answer given to my by my friend was (Note: Language we use is VB.NET)
odule Module1
Sub Main()
Dim twenty As Integer
Dim ten As Integer
Dim five As Integer
Dim two As Integer
Dim one As Integer
Dim final As Integer
Console.Write("Enter your amount of money: ")
Dim money As Integer
money = Console.ReadLine()
twenty = (money / 20)
final = (money Mod 20)
ten = final / 10
final = final Mod 10
five = final / 5
final = final Mod 5
two = final / 2
final = final Mod 2
one = final / 1
final = final Mod 1
Console.WriteLine("Number of £20 notes: " & twenty)
Console.WriteLine("Number of £10 notes: " & ten)
Console.WriteLine("Number of £5 notes: " & five)
Console.WriteLine("Number of £2 coins: " & two)
Console.WriteLine("Number of £1 coins: " & one)


Console.ReadLine()
End Sub
End Module
Reply 22
Original post by MissMyDawgs
Oh thanks : ) I've found something else I'm stuck on. I got the answer off my friend but I want to know what is actually going on cos I'm kind of confused.

Question: The user enters an amount of money as a whole number. The program should calculate and display how many £20, £10 and £5 notes and £2 and £1 coins are needed to make up this amount of money. For example, £37 would give 1 x £20, 1 x £10, 1 x £5 and 1 x £. Hint use integer division and modulo operation

Ermm sorry, I know I'm sounding stupid but what is the modulo operation?

Also the answer given to my by my friend was (Note: Language we use is VB.NET)
odule Module1
Sub Main()
Dim twenty As Integer
Dim ten As Integer
Dim five As Integer
Dim two As Integer
Dim one As Integer
Dim final As Integer
Console.Write("Enter your amount of money: ")
Dim money As Integer
money = Console.ReadLine()
twenty = (money / 20)
final = (money Mod 20)
ten = final / 10
final = final Mod 10
five = final / 5
final = final Mod 5
two = final / 2
final = final Mod 2
one = final / 1
final = final Mod 1
Console.WriteLine("Number of £20 notes: " & twenty)
Console.WriteLine("Number of £10 notes: " & ten)
Console.WriteLine("Number of £5 notes: " & five)
Console.WriteLine("Number of £2 coins: " & two)
Console.WriteLine("Number of £1 coins: " & one)


Console.ReadLine()
End Sub
End Module


The modulo operation returns the integer remainder when dividing two integers. So if you had two numbers aa and bb then amodba \bmod{b} would equal the remainder you get when aa is divided by bb.

I'll try to show it by examples:

3mod2=13 \bmod{2} = 1 because when 3 is divided by 2 you are left with a remainder of 1.

47mod4=347 \bmod{4} = 3 because when 47 is divided by 4 you are left with a remainder of 1.

8mod2=08\bmod{2} = 0 because there is no remainder, 2 divides 8 perfectly.

Unfortunately the solution your friend chose appears to be incorrect. I tried running it on my machine with 74 as the input and it gave me four £20 notes, one £10 note, one £5 note and two £2 coins which adds up to £99 not £74.
It'd be inappropriate if I gave you the correct answer but now you know what the modulo function is, do you think you'll be able to come up with something to solve it? I can provide a couple of hints if need be.
Original post by Jarred
The modulo operation returns the integer remainder when dividing two integers. So if you had two numbers aa and bb then amodba \bmod{b} would equal the remainder you get when aa is divided by bb.

I'll try to show it by examples:

3mod2=13 \bmod{2} = 1 because when 3 is divided by 2 you are left with a remainder of 1.

47mod4=347 \bmod{4} = 3 because when 47 is divided by 4 you are left with a remainder of 1.

8mod2=08\bmod{2} = 0 because there is no remainder, 2 divides 8 perfectly.

Unfortunately the solution your friend chose appears to be incorrect. I tried running it on my machine with 74 as the input and it gave me four £20 notes, one £10 note, one £5 note and two £2 coins which adds up to £99 not £74.
It'd be inappropriate if I gave you the correct answer but now you know what the modulo function is, do you think you'll be able to come up with something to solve it? I can provide a couple of hints if need be.

Ok I will try and redo it in a day or 2 and see if I need help with anything. And thanks I understand the modulo operation now :smile: Teacher didn't explain it as clear as you just did so thanks a million
Original post by Jarred
The modulo operation returns the integer remainder when dividing two integers. So if you had two numbers aa and bb then amodba \bmod{b} would equal the remainder you get when aa is divided by bb.

I'll try to show it by examples:

3mod2=13 \bmod{2} = 1 because when 3 is divided by 2 you are left with a remainder of 1.

47mod4=347 \bmod{4} = 3 because when 47 is divided by 4 you are left with a remainder of 1.

8mod2=08\bmod{2} = 0 because there is no remainder, 2 divides 8 perfectly.

Unfortunately the solution your friend chose appears to be incorrect. I tried running it on my machine with 74 as the input and it gave me four £20 notes, one £10 note, one £5 note and two £2 coins which adds up to £99 not £74.
It'd be inappropriate if I gave you the correct answer but now you know what the modulo function is, do you think you'll be able to come up with something to solve it? I can provide a couple of hints if need be.

Quick question, how can I choose what decimal place I want a decimal number to be rounded to. So for example I want it to 4 decimal places, how do I do that?
Reply 25
Original post by MissMyDawgs
Quick question, how can I choose what decimal place I want a decimal number to be rounded to. So for example I want it to 4 decimal places, how do I do that?


There are a few ways of doing it but usually if I want to round a number (let's call it num1) to a specific number of decimal places (let's call this amount num2) then I'd use:

Math.Round(num1, num2)

So in your case, you'd go with:

Math.Round(num1, 4)

(obviously replacing num1 with whatever the name of your variable is)
Original post by Jarred
There are a few ways of doing it but usually if I want to round a number (let's call it num1) to a specific number of decimal places (let's call this amount num2) then I'd use:

Math.Round(num1, num2)

So in your case, you'd go with:

Math.Round(num1, 4)

(obviously replacing num1 with whatever the name of your variable is)

Oh I found it moments after asking you but thanks anyways. Ill be back with more questions so dont go anywhwere :wink:
Reply 27
Original post by MissMyDawgs
Oh I found it moments after asking you but thanks anyways. Ill be back with more questions so dont go anywhwere :wink:


No problem :smile:
Original post by Jarred
No problem :smile:

Quick question, what do I have to do so that I can display Names in alphabetical order. So the input would be 3 names then for the output they would be put in order of alphabet
So any of you thought about ideas for your comp 4 project? :smile:


Posted from TSR Mobile
Reply 30
Original post by MissMyDawgs
Quick question, what do I have to do so that I can display Names in alphabetical order. So the input would be 3 names then for the output they would be put in order of alphabet


It's not something I've done for a while but the way I'd do it is create an array of Char (characters) for each word, and then compare the characters between each word. However, since VB.NET is so much kinder than other languages (perhaps too kind since it does everything for you, where's the fun in that? :tongue:) there's a very quick way of doing it because there's a built in method for you. The CompareTo() method.

If you have two strings called string1 and string2 then string1.CompareTo(string2) will return an integer based on their alphabetical ordering from each other.

If string1 comes before string2 in the alphabet then you get a negative number.
If they are the same word then you get zero.
And if string1 comes after string2 in the alphabet then you get a positive number.

Now it's simply a case of comparing them to each other using some If statements and you're golden.
Reply 31
...
(edited 10 years ago)
Reply 32
Original post by Jarred
It's not something I've done for a while but the way I'd do it is create an array of Char (characters) for each word, and then compare the characters between each word. However, since VB.NET is so much kinder than other languages (perhaps too kind since it does everything for you, where's the fun in that? :tongue:) there's a very quick way of doing it because there's a built in method for you. The CompareTo() method.

If you have two strings called string1 and string2 then string1.CompareTo(string2) will return an integer based on their alphabetical ordering from each other.

If string1 comes before string2 in the alphabet then you get a negative number.
If they are the same word then you get zero.
And if string1 comes after string2 in the alphabet then you get a positive number.

Now it's simply a case of comparing them to each other using some If statements and you're golden.


Thanks this worked perfectly, what about 3 names? The sheet says to use a nested if statement but I'm not entirely sure how this will work out

This is what I've got so far:

Spoiler

(edited 10 years ago)
Reply 33
Original post by blockslia
Thanks this worked perfectly, what about 3 names? The sheet says to use a nested if statement but I'm not entirely sure how this will work out

This is what I've got so far:

Spoiler



Yeah a number of nested if statements (if statements within if statements) will be required.

Splitting it all up into cases is a good way of handling it. Think about how name1 and name2 compare to each other, and then within that think of all of the possible situations of where name3 can appear. It might help if you have a think about all of the possible situations that can occur (there are six possible ways of ordering 3 items, so six cases to consider) and craft a set of nested ifs from that.

I've got a very faint skeleton here though have a go on your own first if you haven't already. It's very bare so you still have to do most of the work yourself but naturally that's the best way to learn, this just gives you a vague starting point.

Spoiler



If you're stuck or if you work it out without understanding what you've done then give me a shout :smile:
(edited 10 years ago)
Reply 34
Original post by Jarred
Yeah a number of nested if statements (if statements within if statements) will be required.

Splitting it all up into cases is a good way of handling it. Think about how name1 and name2 compare to each other, and then within that think of all of the possible situations of where name3 can appear. It might help if you have a think about all of the possible situations that can occur (there are six possible ways of ordering 3 items, so six cases to consider) and craft a set of nested ifs from that.

I've got a very faint skeleton here though have a go on your own first if you haven't already. It's very bare so you still have to do most of the work yourself but naturally that's the best way to learn, this just gives you a vague starting point.

Spoiler



If you're stuck or if you work it out without understanding what you've done then give me a shout :smile:



EDIT: I asked a question earlier but I fully understand it now, I just have a little problem with the program, I tried out different combinations and found out that for some the programme doesn't work correctly e.g. Name1 = c, Name2= a, Name3= z but it doesnt come up right.

Spoiler

(edited 10 years ago)
Reply 35
Original post by Theoldme
EDIT: I asked a question earlier but I fully understand it now, I just have a little problem with the program, I tried out different combinations and found out that for some the programme doesn't work correctly e.g. Name1 = c, Name2= a, Name3= z but it doesnt come up right.

Spoiler



Yeah when I run it under those conditions I also get an incorrect sorting, I've had a look through the code and I think I've found the culprit marked out below:


If (name1 < name2) And (name1 < name3) Then
Console.Write(name1 & " ")
If name2 < name3 Then
Console.Write(name2 & " " & name3)
Else
Console.WriteLine(name3 & " " & name2)
End If
Else
If (name2 < name1) And (name2 < name3) Then
Console.Write(name2 & " ")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If name1 < name3 Then
Console.Write(name3 & " " & name1)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End If
Else
Console.Write(name3 & " ")
If name1 < name2 Then
Console.Write(name1 & " " & name2)
Else
Console.Write(name2 & " " & name1)
End If
End If
End If


See how within the if block, the program writes name3 before name1 when the if statement itself has found that name1 should come before name 3.

Console.Write(name3 & " " & name1) needs to be changed to:
Console.Write(name1 & " " & name3)

Note that this is not the only error in the program though, if you try sorting "c", "a" and "b" as name1, name2 and name3 respectively then you'll get an issue where it only writes "a" to the screen.
Reply 36
Original post by Jarred
Yeah when I run it under those conditions I also get an incorrect sorting, I've had a look through the code and I think I've found the culprit marked out below:


If (name1 < name2) And (name1 < name3) Then
Console.Write(name1 & " ")
If name2 < name3 Then
Console.Write(name2 & " " & name3)
Else
Console.WriteLine(name3 & " " & name2)
End If
Else
If (name2 < name1) And (name2 < name3) Then
Console.Write(name2 & " ")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If name1 < name3 Then
Console.Write(name3 & " " & name1)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End If
Else
Console.Write(name3 & " ")
If name1 < name2 Then
Console.Write(name1 & " " & name2)
Else
Console.Write(name2 & " " & name1)
End If
End If
End If


See how within the if block, the program writes name3 before name1 when the if statement itself has found that name1 should come before name 3.

Console.Write(name3 & " " & name1) needs to be changed to:
Console.Write(name1 & " " & name3)

Note that this is not the only error in the program though, if you try sorting "c", "a" and "b" as name1, name2 and name3 respectively then you'll get an issue where it only writes "a" to the screen.

Oh thanks, i just redone the whole thing and all combinations seem to work. I had a little peak through your acadamic info and saw A* for computing :P I won't be doing computing for A2 but I was wondering how hard it was for you to achieve that grade? Is it similar to AS at all or a whole new different thing? Lol at my college I heard my teacher say something about 1 student every 1 or 2 years achieving an A* in computing -____-
Reply 37
Original post by Theoldme
Oh thanks, i just redone the whole thing and all combinations seem to work. I had a little peak through your acadamic info and saw A* for computing :P I won't be doing computing for A2 but I was wondering how hard it was for you to achieve that grade? Is it similar to AS at all or a whole new different thing? Lol at my college I heard my teacher say something about 1 student every 1 or 2 years achieving an A* in computing -____-


Ah that's good that it's working :smile: I remember having a similar task when I was in the first term of AS, good times. Luckily you'll learn another way of sorting by the time you get to the end of the year, with the "bubble sort"

Yeah, I wouldn't say it was particularly hard in the traditional sense, I mean, it was easy to understand what was going on, I never met a topic where I just thought "What the hell is going on". The real difficulty came in how much work I had to do though. I did a lot..

A2 is split into two modules, COMP3 and COMP4. COMP3 is an exam at the end of the year and COMP4 is a coursework project. COMP3 is fairly similar to AS really, it's more theory, sort of a mix between programming theory and more general computer science. I didn't find either difficult. But COMP4 required so much time. You have to develop a full on software package for a client, going right from the start by researching it and analysing the problem you're trying to solve, right through to the design, the production and the testing and maintenance of the program. You even have to write a little user manual for it. And it's a proper program too, with a graphical interface, rather than just being a console app.

It wasn't difficult, and it was a lot of fun in some ways, but I put so much time into it. Too much perhaps. Just to give you an idea of how comprehensive it was, my final submission was over 600 pages long and over 110,000 words in length and the bulk of that was done in two months :tongue: My teachers had terrible organisation of the whole project.

I loved my program though :h: It was a Further Maths learning system called "Explore", it could do all sorts of crazy things. The main focus though was on the dynamic generation of completely random questions, which would change every time with infinite number of possibilities. The program would then calculate the answers in real time, and mark your work for you. There was also a little messaging system, lessons, past exam questions (with no randomness) and best of all, if you were an admin, you could delete all of the databases that the program used by clicking a big fat red "PURGE!" button :tongue:

It felt stressful at the time, but oddly enough, it was really fun too.
Reply 38
Original post by Jarred
Ah that's good that it's working :smile: I remember having a similar task when I was in the first term of AS, good times. Luckily you'll learn another way of sorting by the time you get to the end of the year, with the "bubble sort"

Yeah, I wouldn't say it was particularly hard in the traditional sense, I mean, it was easy to understand what was going on, I never met a topic where I just thought "What the hell is going on". The real difficulty came in how much work I had to do though. I did a lot..

A2 is split into two modules, COMP3 and COMP4. COMP3 is an exam at the end of the year and COMP4 is a coursework project. COMP3 is fairly similar to AS really, it's more theory, sort of a mix between programming theory and more general computer science. I didn't find either difficult. But COMP4 required so much time. You have to develop a full on software package for a client, going right from the start by researching it and analysing the problem you're trying to solve, right through to the design, the production and the testing and maintenance of the program. You even have to write a little user manual for it. And it's a proper program too, with a graphical interface, rather than just being a console app.

It wasn't difficult, and it was a lot of fun in some ways, but I put so much time into it. Too much perhaps. Just to give you an idea of how comprehensive it was, my final submission was over 600 pages long and over 110,000 words in length and the bulk of that was done in two months :tongue: My teachers had terrible organisation of the whole project.

I loved my program though :h: It was a Further Maths learning system called "Explore", it could do all sorts of crazy things. The main focus though was on the dynamic generation of completely random questions, which would change every time with infinite number of possibilities. The program would then calculate the answers in real time, and mark your work for you. There was also a little messaging system, lessons, past exam questions (with no randomness) and best of all, if you were an admin, you could delete all of the databases that the program used by clicking a big fat red "PURGE!" button :tongue:

It felt stressful at the time, but oddly enough, it was really fun too.

Hey I got 2 questions, the topic is repetition and these questions are related to "Executing a loop a specific number of times".

For my first one, it says "Expand your solution to Question 5 (Spoiler below) and ask the user how many rows of stars they want to see. Display the rectangle of stars as specified by the user. Hint you will need to nest one For loop inside another"

So I've already done question 5 which asks for how many stars the user wants to see in one row. My Code =

Spoiler


If possible please try helping me by giving hints rather than the answer and if I am still stuck by Wednesday ill let you know.

Anyway my second question "Ask the user to enter 10 numbers. display the largest number entered" I think I can do this but keeping in mind that this topic is "Repetition - For Loop" I'm not sure how it will apply to it. Any suggestions??
Reply 39
Personally, I found the COMP1/COMP2 exams easy.

For COMP2, you need to have good memory to learn the content and basic maths. Obviously some understanding may be involved, but I think the content is very easy to understand when comparing it to science subjects such as physics.

For COMP1, you need to be very good at programming (both reading and writing programs). You can't learn how to program in a few days, so prepare well in advance. If you are good at maths, you are more likely to be good at programming.

Quick Reply

Latest