Help for an Algorithm Writing Noob

dreadman

Member
Aug 11, 2008
48
0
61
Hi everyone.

Just recently pushed myself to go back to school and I'm pursuing a course in Info Systems and Management.

However, I have absolutely zero programming experience and sadly, even the entry level algorithm writing that we are doing this semester is giving me grief.

Maybe it's the method of teaching/jumping back into studying after a gap of several years/juggling work full-time and classes, I just can't seem to wrap my brain around it.

Now I have an assignment due and I'm looking for some assistance.
The answer would be nice too but only in addition to the way you would go about doing it.
I think I'd be able to follow better that way


Problem
An instructor has a list of marks representing the scores of students in a test. Each line contains a student id (integer) followed by an integer score in the range 0-100. The last line contains the number -9999.
Sample Data
5000 45
4000 32
1000 75
-9999

Requirements
(a) Write algorithms to read the data and find and print
- The average mark in the exam
- The ID of the student who scored the highest if the highest is unique. If more than one student scored the highest mark, print all of their IDs.
(b) Write an algorithm to print a list of all students with IDs in the range 4000-7000 and the score each obtained.
(c) Clearly explain the main steps.

Thanks in advance for any help that is provided.
 

Apathetic

Platinum Member
Dec 23, 2002
2,587
6
81
Nobody here is going to simply write your homework assignment for you. However, that doesn't mean we won't try to help you out.

You need to write a program which performs several steps. Deal with them one at a time - otherwise you'll probably get overwhelmed. The first thing you need to do is read some data from a file. Write a very tiny program that does just that. Even if it can only read one line at first, that's OK. Start with that, and then ask yourself how can I change this so that it reads all the data? Once that's solved, go from there.

Dave
 

Cogman

Lifer
Sep 19, 2000
10,283
134
106
Considering that this is a pretty simple problem, it is really quite hard to give any help without giving the solution.

Like Apathetic said, break the problem into parts, then break those parts into parts. The ability to do that is very necessary for computer programming.
 

dreadman

Member
Aug 11, 2008
48
0
61
It would be highly ridiculous for me to expect someone to do my homework for me and if that is the way it came across...that was never the intention.

I respect that you all are probably light years ahead of this pretty simple problem but I thought the fact that I'm a beginner with no experience but totally willing to learn would have at least reminded others of their beginner days.

Thanks for the suggestions so far...as difficult as it currently seems, I'll try the step by step
 

Cogman

Lifer
Sep 19, 2000
10,283
134
106
It would be highly ridiculous for me to expect someone to do my homework for me and if that is the way it came across...that was never the intention.

I respect that you all are probably light years ahead of this pretty simple problem but I thought the fact that I'm a beginner with no experience but totally willing to learn would have at least reminded others of their beginner days.

Thanks for the suggestions so far...as difficult as it currently seems, I'll try the step by step

The issue, and we have all seen it before, is that just giving an answer tends to make people get false impressions about what they "know". The answer will make sense, and yet, they won't be able to handle a brand new problem that is slightly different. It is a common problem even in industry developers (For example, the "copy-paste" coder who "knows" how to program but not how to write his own program without using someone else's code).

Even so, How about I give you a problem and solution that are similar to your stated problem and hopefully you can glean what it takes.


Say you have a file filled with numbers separated only by spaces. so it might look like this:
Code:
232 4893 283 4903 2837 9023 1782 923 172 829[code]
Write an algorithm that will find the average of the numbers in the file.
After that, find the average of the values greater then 1000.

Now, if I was going to write an algorithm that fulfills those requirements, I would say "Ok, what needs to be done". In my mind the steps just sort of form (I really don't know the process that I'm using)


1. Open the file
2. Load all the numbers into some sort of array

To get the average
3. sum up the values stored in the array
4. divide that sum by the total number of elements in the array to get the average.

To get the average of numbers over 1000
3. go through each element if the element is > 1000 increase a sum variable by the value of the element and a number of elements variable by 1.
4. divide the sum variable by the number of elements variable.

Of course, this isn't the only way to do this, but it is how I would do it.

So for your problem, look at each of the requirements given, then come up with the steps necessary to complete those requirements. I don't know how thorough your teacher want you to be, but some steps will be as simple as "The requirement says to load the information from a file, so the step is to load the information from a file.) While others will require multiple steps to be thorough.
 

bobross419

Golden Member
Oct 25, 2007
1,981
1
0
Is your teacher looking for pseudo-code?

I would take each item above as a step in the program and make a sub-routine(function) out of each:

OpenFile();
ReadFile();
GetSum();
GetAverage();
..etc();

Then tackle each step on its own... Some, like OpenFile() really doesn't need anything extra. I'd personally use a hash (associative array), but a multi-dimensional array, or just two individual arrays tied together with a counter can work as well.

I'm not going to go through the whole thing, but here is an example of how I would read the file into two individual arrays:

Code:
sub ReadFile()
{
   int lines = get NumberofLines in file; #need to determine array size
   array studentID[lines - 1]; #array is 0-base so have to subtract 1
   array score[lines - 1]; #array is 0-base so have to subtract 1
   int counter = 0; #this is just a way to keep both even
   for each line  #read through the file one line at a time
   {
       studentID[counter] = text before space; #everything before the space is an ID
       score[counter] = text after space; #everything after the space is the score
       counter++; #iterate the counter so it is ready for the next line
   }
   return studentID[],score[]; #send the newly created arrays back to the calling function
}

This is a pretty dumbed down version and leaves a lot of things to be desired, but for pseudo-code it should be enough to get the job done. Its a starting point at least. This might be more involved than what your teacher is looking for, but I hope it helps you get a feel for the process a little better.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
You asked about this in terms of algorithms, not code, so I'll add a little bit along those lines. The common thread in what the others have told you is the idea of problem decomposition. This has nothing specifically to do with programming. It's been a key part of process engineering since long before it was called "process engineering."

Computers are simple beasts. They understand numbers, and that's about it. So any problem that is more complex than "add 4 to 5 and store the answer" is going to have to be broken down.

Suppose I tell you "replace the water filter in my refrigerator." Could you describe that process to someone who never saw a refrigerator, or a filter, in such a way that they could quickly and directly accomplish the task? That's what you have to do for the computer. That is the essential aspect of algorithm design. If you teach yourself to break down problems far enough that a generic device could be told how to solve them, then you will have no real struggle translating the resulting recipe into program code. If you never learn to do that, then you can teach yourself as much about code as you like, but you will never know how to program.
 

AyashiKaibutsu

Diamond Member
Jan 24, 2004
9,306
3
81
Make an arraylist of objects that contain the ID and score. Parse input into array list. Loops. Profit.
 

dreadman

Member
Aug 11, 2008
48
0
61
I just wanted to say you guys ROCK!!!

Thanks to everyone who took the time out to help point me in the right direction.
I really appreciate it.
Providing the answer will not help me in the end. So it's all good.

I'm off from work tomorrow so I fully intend to sit down, take my time and get it done.
Even if it takes me all day.
Thankfully this semester, all we are doing is problem solving using pseudocode
so while real code isn't necessary this time, it will be in the future.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
I just wanted to say you guys ROCK!!!

Thanks to everyone who took the time out to help point me in the right direction.
I really appreciate it.
Providing the answer will not help me in the end. So it's all good.

I'm off from work tomorrow so I fully intend to sit down, take my time and get it done.
Even if it takes me all day.
Thankfully this semester, all we are doing is problem solving using pseudocode
so while real code isn't necessary this time, it will be in the future.

I feel like this is a mistake. How are you supposed to know how to decompose a problem if you don't know the base elements (code, datatypes, libraries, etc) that you have to decompose to?
 
Last edited:

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I feel like this is a mistake. How are you supposed to know how to decompose a problem if you don't know the base elements (code, datatypes, libraries, etc) that you have to decompose to?

It really doesn't need to be expressed in terms of any particular language structure at that level. Knuth invented... Mix I think it was called... a sort of ideal assembly language for his Art of Computer Programming. I think what you need is an understanding of command execution, flow of control, conditional branching, logical expressions, jumps, etc. Not that I think it would be best to learn those things completely independent of learning a language. I didn't. But I don't think the one is entirely dependent on the other.
 

bobross419

Golden Member
Oct 25, 2007
1,981
1
0
I tried programming before learning pseudo-code, self study, and I just couldn't get anywhere. After taking a pseudo-code class, I was able to really understand the process better. Learning the process without having to worry about the syntax really helped me out. It might not be the best way for everybody, but I'm sure it works for some people. This leaves me free to focus on the syntax of a language that I'm picking up than have to worry about syntax and process.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |