School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,481 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,774 people online right now. Registration is fast and FREE... Join Now!




Advanced Array Manipulation

 

Advanced Array Manipulation, 2D Array Problem

jpconleyiv

28 Apr, 2009 - 01:55 PM
Post #1

D.I.C Head
Group Icon

Joined: 9 Mar, 2009
Posts: 88



Thanked: 4 times
My Contributions
Hey everyone!! So, this is what I'm working with (school problem). An application in which I have to design that allows a professor to enter a student name and 10 quiz scores for each of the 20 students. The putput lists each students name and total points for each students eight highest-scoring quizzes.

This is what I developed so far. My real problem is listing the eight highest scores, which i have yet to add. I'm just looking for people to take a look at it and if you see something I can correct or possibly teach me a better way to do it that would be great. Again, I am not looking to have the answer handed to me that's not why I am here, I am looking for any help that is offered so that one day I can return those favors to aspiring programmers like myself.
CODE

     Start

            string name
            num  students = 21
            num quizScore [students]
            num x = 1
                   get name
                        while x < students
                get quizScore [x]
                 x=x +1
endwhile
        perform BubbleSort (num quizScore[], num students)
        DisplayArray (num quizScore[], num students)
Stop

void BubbleSort (num quizScore[], num students)

void DisplayArray(num quizScore[], num students)
    num x = students – 1
    while x > 0
        print name, quizScore[x]
        x = x – 1
    endwhile
return

Thanks for all of your time!!!! Much appreciated!!!!


User is offlineProfile CardPM
+Quote Post


SixOfEleven

RE: Advanced Array Manipulation

29 Apr, 2009 - 04:16 PM
Post #2

Code Guru
Group Icon

Joined: 18 Oct, 2008
Posts: 2,910



Thanked: 165 times
Dream Kudos: 725
Expert In: C, C#, XNA, Game Programming, Programming Concepts

My Contributions
QUOTE(jpconleyiv @ 28 Apr, 2009 - 01:55 PM) *

Hey everyone!! So, this is what I'm working with (school problem). An application in which I have to design that allows a professor to enter a student name and 10 quiz scores for each of the 20 students. The putput lists each students name and total points for each students eight highest-scoring quizzes.

This is what I developed so far. My real problem is listing the eight highest scores, which i have yet to add. I'm just looking for people to take a look at it and if you see something I can correct or possibly teach me a better way to do it that would be great. Again, I am not looking to have the answer handed to me that's not why I am here, I am looking for any help that is offered so that one day I can return those favors to aspiring programmers like myself.
CODE

     Start

            string name
            num  students = 21
            num quizScore [students]
            num x = 1
                   get name
                        while x < students
                get quizScore [x]
                 x=x +1
endwhile
        perform BubbleSort (num quizScore[], num students)
        DisplayArray (num quizScore[], num students)
Stop

void BubbleSort (num quizScore[], num students)

void DisplayArray(num quizScore[], num students)
    num x = students – 1
    while x > 0
        print name, quizScore[x]
        x = x – 1
    endwhile
return

Thanks for all of your time!!!! Much appreciated!!!!


I think you would want a 2D array like this:

CODE

num quizscores[number of students][number of quizzes]


for the quiz scores and just a single dimension array for the names

CODE

string students[number of students]


To read in the information you would need two nested loops. The outer one would count the number of students and the inner one would count the number of quizzes.

CODE

num x = 1
num y = 1
while x < number of students + 1
    while y < number of quizzes + 1
        y = y + 1
    end while
    x = x + 1
end while


That should help you get started. If you have further problems just leave a post about what you are unclear about.
User is offlineProfile CardPM
+Quote Post

jpconleyiv

RE: Advanced Array Manipulation

29 Apr, 2009 - 05:27 PM
Post #3

D.I.C Head
Group Icon

Joined: 9 Mar, 2009
Posts: 88



Thanked: 4 times
My Contributions
Ok so this what I have worked out since the last post, Thank you SixOfEleven. What I am still racking on are these few things.
1. Is my variable declared correctly- string name [num students]
2.Is it ok to initiate quizzes to 0
3. After the two nested loops, and once in the display module how do I set it up to know what the eight highest score are. At the end it has to print students name, and the total points for each students eight highest scoring quizzes.

CODE



Start

string name [num students]
num  students = 21
num quizzes = 0
num quizScore [num students] [num quizzes]
num x = 1
num y = 1
    get name, quizScore
while x < students + 1
    while y < quizzes + 1
y = y + 1
endwhile
        x=x +1
    endwhile

perform BubbleSort (num quizScore[], num students)
DisplayArray (num quizScore[], num students)
Stop

void BubbleSort (num quizScore[], num students)

void DisplayArray(num quizScore[], num students)
    num x = students – 1
    while x > 0
        print name, quizScore[x]
        x = x – 1
    endwhile
return

Thanks Again!!!!
User is offlineProfile CardPM
+Quote Post

SixOfEleven

RE: Advanced Array Manipulation

29 Apr, 2009 - 05:48 PM
Post #4

Code Guru
Group Icon

Joined: 18 Oct, 2008
Posts: 2,910



Thanked: 165 times
Dream Kudos: 725
Expert In: C, C#, XNA, Game Programming, Programming Concepts

My Contributions
QUOTE(jpconleyiv @ 29 Apr, 2009 - 05:27 PM) *

Ok so this what I have worked out since the last post, Thank you SixOfEleven. What I am still racking on are these few things.
1. Is my variable declared correctly- string name [num students]
2.Is it ok to initiate quizzes to 0
3. After the two nested loops, and once in the display module how do I set it up to know what the eight highest score are. At the end it has to print students name, and the total points for each students eight highest scoring quizzes.

CODE



Start

string name [num students]
num  students = 21
num quizzes = 0
num quizScore [num students] [num quizzes]
num x = 1
num y = 1
    get name, quizScore
while x < students + 1
    while y < quizzes + 1
y = y + 1
endwhile
        x=x +1
    endwhile

perform BubbleSort (num quizScore[], num students)
DisplayArray (num quizScore[], num students)
Stop

void BubbleSort (num quizScore[], num students)

void DisplayArray(num quizScore[], num students)
    num x = students – 1
    while x > 0
        print name, quizScore[x]
        x = x – 1
    endwhile
return

Thanks Again!!!!


You are getting closer but not quite. The order of your variables is a little wrong and the declaration is not quite right. You would want to put them like this:

CODE

num  students = 20
num quizzes = 10
string name [students]
num quizScore [students] [quizzes]


Your while loops are not quite right either, I admit I omitted something in my previous post you need to set y = 1 before you start the inner loop. You would want something along this lines:

CODE

while x < students + 1
        get name[x]
        y = 1
    while y < quizzes + 1
            get quizScore[x][y]
            y = y + 1
        endwhile
        x=x +1
endwhile


Can you see why you would want to do that?

After you do that you will want to make a second loop that would go through each student, copy their scores to an array, sort that array and display the results. From what I've shown you see if you can figure it out. If you can't feel free to leave another post and I'll try and help you out. smile.gif
User is offlineProfile CardPM
+Quote Post

jpconleyiv

RE: Advanced Array Manipulation

1 May, 2009 - 06:05 AM
Post #5

D.I.C Head
Group Icon

Joined: 9 Mar, 2009
Posts: 88



Thanked: 4 times
My Contributions
I GOT IT!!!!! I think.......Lol
Check it out SixOfEleven!!!!!!

CODE

num  students = 21
num quizzes = 11
string name [students]
num quizScore [students] [quizzes]
num x = 1
num y = 1

while x < students
        get name[x]
        y = 1
    while y < quizzes
            get quizScore[x][y]
            y = y + 1
        endwhile
        perform BubbleSort (num quizScore[][])
        x=x +1
endwhile

DisplayArray (num quizScore[][], string name[])

Stop

void BubbleSort (num quizScore[][])

void DisplayArray(num quizScore[][], string name[])
num v = 3
num y
num quizzes = 11
num TotalScore = 0
num students = 21
    y = 1
          while y < students
      while v < quizzes
TotalScore = TotalScore + quizScore[y][v]
      v=v + 1
endwhile
print name[y], TotalScore
y = y + 1
v = 3
endwhile
return


Tell me what you think, this is what I turned in.

User is offlineProfile CardPM
+Quote Post

SixOfEleven

RE: Advanced Array Manipulation

1 May, 2009 - 06:18 AM
Post #6

Code Guru
Group Icon

Joined: 18 Oct, 2008
Posts: 2,910



Thanked: 165 times
Dream Kudos: 725
Expert In: C, C#, XNA, Game Programming, Programming Concepts

My Contributions
QUOTE(jpconleyiv @ 1 May, 2009 - 06:05 AM) *

I GOT IT!!!!! I think.......Lol
Check it out SixOfEleven!!!!!!

CODE

num  students = 21
num quizzes = 11
string name [students]
num quizScore [students] [quizzes]
num x = 1
num y = 1

while x < students
        get name[x]
        y = 1
    while y < quizzes
            get quizScore[x][y]
            y = y + 1
        endwhile
        perform BubbleSort (num quizScore[][])
        x=x +1
endwhile

DisplayArray (num quizScore[][], string name[])

Stop

void BubbleSort (num quizScore[][])

void DisplayArray(num quizScore[][], string name[])
num v = 3
num y
num quizzes = 11
num TotalScore = 0
num students = 21
    y = 1
          while y < students
      while v < quizzes
TotalScore = TotalScore + quizScore[y][v]
      v=v + 1
endwhile
print name[y], TotalScore
y = y + 1
v = 3
endwhile
return


Tell me what you think, this is what I turned in.


Looks like it would work. Good job. icon_up.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 03:59AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month