Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Shaun.P

macrumors 68000
Original poster
Jul 14, 2003
1,601
24
Omicron Persei 8
Hey,

I am in my first year at university and I am doing computer science. I am finding the programming difficult because it is very problem solving orientated.

I have to sit a programming exam a week today (I have to type the solution to a problem, the problem was given out one week ago).

I started working on the problem today. I managed to get some basic concepts done however I am uncertain how to work out the winner and with the number of votes.

I have scanned what I have programmed so far, and the sheet we were given with the problem. When I sit the exam I will not be allowed to take anything in with me, however I can work on the problem as much as I like beforehand.

The programming language used is Ada.
 

Shaun.P

macrumors 68000
Original poster
Jul 14, 2003
1,601
24
Omicron Persei 8
Also, I should've mentioned: I'm don't want exact Ada code, but merely suggestions on how to solve the problem, i.e. use an array, for loop etc.

We haven't really covered advanced stuff only stuff like while, for, if, arrays, put, get, etc, etc.

Thanks for any help.
 

mdavey

macrumors 6502a
Nov 1, 2005
506
1
FearFactor47 said:
I am uncertain how to work out the winner and with the number of votes.

Well the first thing to realise is that your tutor hasn't given you a finished solution - that applies both to the code and the data storage. You are going to need to set up some kind of data storage before you enter the loop and then update the appropriate part of that storage for each row you read in.

You mentioned that you have done arrays - that is one way you could solve the data storage problem. If you have done structures or linked lists, then you might be able to employ those techniques. Or you could just use a bunch of individual variables.

I guess the biggest thing to remember is that University isn't like school. At school, you can be confident of getting the highest marks just by knowning the material that your teacher presented. They call it "reading a subject" at University for a reason ;) I cannot emphasise how important it is to:

# review the notes you took in your lectures and labs
# make sure you thoroughly read the course material and ask your lecturer to explain anything you don't understand
# read arround the subject, starting with the suggested reading list and then researching and cross-referencing texts, periodicals, etc.

Best of luck
 

Shaun.P

macrumors 68000
Original poster
Jul 14, 2003
1,601
24
Omicron Persei 8
Ok I'm confused?

My tutor? The program that is written, I wrote. Secondly, the program is already setup to read data from a text file with a string of numbers then the vote selection.

I don't know how to work out a way to find basically the maximum amount of recurrences of vote selection. How could I do this?
 

mdavey

macrumors 6502a
Nov 1, 2005
506
1
FearFactor47 said:
Ok I'm confused?

My tutor? The program that is written, I wrote. Secondly, the program is already setup to read data from a text file with a string of numbers then the vote selection.

Sorry, I misunderstood. I got the impression from the question sheet that you were supplied with a skeleton program, which you have extended.

I don't know how to work out a way to find basically the maximum amount of recurrences of vote selection. How could I do this?

You need to keep a count for each candidate.
 

Shaun.P

macrumors 68000
Original poster
Jul 14, 2003
1,601
24
Omicron Persei 8
Oh no, the skeleton program simply had stuff like 'begin' and end' the code there I typed.

How do I keep a count?
 

superbovine

macrumors 68030
Nov 7, 2003
2,872
0
You should goto your professor or the teacher assistant and ask for help. the program isn't very hard. I think you need to sit down with someone and they will have to explain to how to go about solving the problem. Have you tried drawing a flow chart of how the program should work logical? Do you know how it should work logically? Have you been reading your text? Do you know how to solve the problem using pen & paper? It very easy, just totally the votes then select winner and the other output. Well, all you have to is write a program to the exact same thing. In order to totally votes, you need to store the count some place right? etc etc.

The way most beginners should code is to do it in small sections. the first part you should get is put able to parse all your input. You can google around for code on how to parse text in ada. That solution is probably in your book which you probably haven't read. After that, i'd suggest you goto your professor and say hey, I can do this much, but i am stuck here. They will much more willing to help you if you took some steps in the right direction.
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
I guess I would first ask what "tools" you're supposed to have available to you at this point. Can you use classes, structures, multidimensional arrays, hashtables, pointers, multiple functions, etc.? Or is your toolset more basic? There are multiple ways to solve the problem but I assume you'll be limited in some way as to what you're supposed to know.
 

Jordan72

macrumors member
Nov 23, 2005
88
0
I'm a newbie, but I'll take a whack at this.

I'd make a Vote Class. The Vote class would generate vote objects as it read the data from the input. Each object would include field data: phone number(a character array, so you do some comparison) and an integer for the Candidate. I would write simple setter and getter methods for the field data so as the data is read in, each vote object's data is intializized and ready to be manipulated by a Tally Class below.

Then I would make the Tally Class. The Tally Class would have a data field that consisted of the total number of calls, total number of votes and unique phone numbers. I would create methods for this class that counted the votes, tested for duplicate phone numbers, etc.

I think that would be a neat and tidy way to begin organizing things, just so you have something easy to begin with. When you think of a new things you have to do, just add a method or field data on need to have basis.
 

Shaun.P

macrumors 68000
Original poster
Jul 14, 2003
1,601
24
Omicron Persei 8
Thank you for all your help. AFAIK Ada is a very complex language, but we haven't covered all of the advanced stuff (only started learning this programming language in mid September). My programming is rusty but what I find difficult is using what I have available to solve a problem. For example, I know the votes need to be stored, (using an array?) but I don't know how to implement it. Argh! I think I might go and see my lecturer, however I don't think they can help too much.

Someone above said that I probably have a book which I haven't bothered reading? Truth is, I don't have a book on Ada. We don't use it in the class so I never bought it. Maybe I should.

Why are we using Ada? Is it easier or something compared to the other languages? Is it a 'real' language? I don't know why the uni didn't pick something more popular.
 

TrumanApple

macrumors member
Jan 2, 2005
87
0
FearFactor47 said:
Thank you for all your help. AFAIK Ada is a very complex language, but we haven't covered all of the advanced stuff (only started learning this programming language in mid September). My programming is rusty but what I find difficult is using what I have available to solve a problem. For example, I know the votes need to be stored, (using an array?) but I don't know how to implement it. Argh! I think I might go and see my lecturer, however I don't think they can help too much.

Someone above said that I probably have a book which I haven't bothered reading? Truth is, I don't have a book on Ada. We don't use it in the class so I never bought it. Maybe I should.

Why are we using Ada? Is it easier or something compared to the other languages? Is it a 'real' language? I don't know why the uni didn't pick something more popular.

well i have a pretty strong background in ada... ada is used for DOD stuff and isnt really widly used.

Basically you are going to use a bunch of parrallel arrays...

use one to count the number of votes (indexed by the canidate number), remembering that the sum of the entire array is the number of total votes... have an array of phone numbers and on each input search that so you know whether that phone number has tried to vote...

its 3AM so i wont get any more detailed
but just remember parrallel arrays
 

TrumanApple

macrumors member
Jan 2, 2005
87
0
FearFactor47 said:
Thank you for all your help. AFAIK Ada is a very complex language, but we haven't covered all of the advanced stuff (only started learning this programming language in mid September). My programming is rusty but what I find difficult is using what I have available to solve a problem. For example, I know the votes need to be stored, (using an array?) but I don't know how to implement it. Argh! I think I might go and see my lecturer, however I don't think they can help too much.

Someone above said that I probably have a book which I haven't bothered reading? Truth is, I don't have a book on Ada. We don't use it in the class so I never bought it. Maybe I should.

Why are we using Ada? Is it easier or something compared to the other languages? Is it a 'real' language? I don't know why the uni didn't pick something more popular.

Oh yeah... type my_Array_type is array (1..100) of Integer; i may be a little off but that is basically the array type declaration... then declare a variable of that type
myArray:myArrayType;

You can also make an unconstrained array
type my_Array_type is array (Natural <>) of Integer;
and then constrain it in the declaration
myArray:myArrayType(1..50); or whatever you want the numbers to be;
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
I'm not so sure Ada is that complex. It and Pascal share a lot of similarities (IIRC Ada developed out of Pascal) and Pascal was taught in schools when I was a kid. Pascal was taught as it's very strict and makes you write programs 'properly'.

If you don't 'get' Pascal/Ada you won't get C++. C++ is waaaaay harder.

I'm not sure Ada and Pascal are that widely used commercially except for legacy code. Most stuff now is written in VB, C, C++ and Java (and objective-C on the Mac). Having said that knowing the other languages isn't a bad thing. Some people were getting very good money checking COBOL systems in the City of London at the time of the Y2K thing. Shame nobody told me as I did a lot of COBOL programming when I did my A-levels....I was pretty good at it:(
 

mdavey

macrumors 6502a
Nov 1, 2005
506
1
FearFactor47 said:
Truth is, I don't have a book on Ada. We don't use it in the class so I never bought it. Maybe I should.

Definitely you should read a book on Ada. There is no need to actually buy it, you might find one available in your Uni library. Go back and reread paragraphs 3 and 4 of my first post.

You should be reading everything you can get your hands on. All your spare time should be taken up with reading stuff. That is what University is about and it is essential if you want to get a half-way decent mark. I'll repeat what I said in my first post: at University, the lecturer will not tell you everything you need to know - you need to read around your subject to understand it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.