473,320 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

C++ Parallel Arrays - Storing and Sorting

Hi,

I'm working on a program that takes the following input from the user:

Student Name, Student Number, and Student GPA

The information is then supposed to be stored in three separate arrays.

Prior to sending the output to the screen, a bubble sort has to be performed
so that it's sorted by Student Name.

Here is the code I have so far, but I'm having the following problems:

1 - I'm unsure about the first while loop for input (need to know what I
should be comparing it to, so that it breaks properly.

2 - I need to know more about the sorting of parallel arrays

Expand|Select|Wrap|Line Numbers
  1.     int studentNumber[50];
  2.     string studentName[50],temp;
  3.     double studentGPA[50],temper;
  4.     int i=0,tmp;
  5.     int x = 0;
  6.     int y = 0;
  7.     int ia = 0;
  8.     int length = 0;
  9.  
  10.  /* Prompt user for input of studentNumber, studentName, and studentGPA */
  11.     while (studentNumber[i] != 0)
  12.     {
  13.  
  14.  
  15.         cout << "Enter Student Number: ";
  16.         cin >> studentNumber[i];
  17.         cout << endl;
  18.         cout << "Enter Student Name: ";
  19.         cin >> studentName[i];
  20.         cout << endl;
  21.         cout << "Enter Student GPA: :";
  22.         cin >> studentGPA[i];
  23.         cout << endl;
  24.         i = i + 1;
  25.     }
Any help is greatly appreciated. I know that it's probably something simple, but my eyes having been looking at the code all afternoon and I'm missing something.

Earl
Mar 12 '07 #1
8 5211
Ganon11
3,652 Expert 2GB
For the while loop, why not add a char variable before the loop initialized to 'Y'. Inside the loop, ask the user, "Do you want to enter more data?" and input into the character. Then your loop condition will be "Continue while the character is 'Y' or 'y'".

For sorting the parallel arrays, it looks like you have the right idea.
Mar 12 '07 #2
For the while loop, why not add a char variable before the loop initialized to 'Y'. Inside the loop, ask the user, "Do you want to enter more data?" and input into the character. Then your loop condition will be "Continue while the character is 'Y' or 'y'".

For sorting the parallel arrays, it looks like you have the right idea.
Many thanks for your help...

I have the while loop working great :)

However, my sort doesn't appear to be working....

Any ideas?

Earl
Mar 12 '07 #3
Many thanks for your help...

I have the while loop working great :)

However, my sort doesn't appear to be working....

Any ideas?

Earl
Well, I did manage to fix the sorting code, but the output to the screen has
something funky going on. If anyone can figure it out, I would be greatful.

Data:

123456 Bakter 3.0
342130 Carson 3.8
111230 King 4.0
234512 Zimmerman 3.1

Output Display:

Mar 12 '07 #4
Ganon11
3,652 Expert 2GB
Very strange...Where are you outputting the data? Can we see just that portion of the code again?

It looks like it is trying to output garbage data, like memory addresses or something.
Mar 12 '07 #5
DeMan
1,806 1GB
I think there may be a slight problem with

Expand|Select|Wrap|Line Numbers
  1. while(studentNumber[i] != 0)
  2. {
  3.   cin >> studentNumber[i];
  4.  
  5.   // other things
  6.   i = i + 1;
  7. }
  8.  
This means you are comparing to an unitialised array value......(I think this may be why Ganon11 suggested adding a "do you want to do more" type statement on the while loop)
Mar 12 '07 #6
I want to thank everyone for their great help :)

I did solve the mystery data output problem that was in my screenshot
earlier.

It was a result of not subtracting '1' from my inner loop counter when
the 'done' condition was met.

The mystery data that you seen on the screen was the contents
of the next array, which hadn't been filled yet :)



Earl
Mar 13 '07 #7
Ganon11
3,652 Expert 2GB
It's always something simple :)

Good to see you figured it out!
Mar 13 '07 #8
I just had to take it section, by section and walk through the logic with some
debugging prints to the screen.

It sure feels good to solve those problems and see the software do exactly what you want it too :)

Earl
Mar 13 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: John | last post by:
Hi all, I've got an issue with session variables in asp pages. I need to make a decision that I think you can hopefully help me out here. When a session starts on the iss server I need to...
9
by: Till Crueger | last post by:
Hi, I have to implement some simple sorting algorithm. I am NOT asking for you to do my homework, but my question is rather on how to store the integers. I recall reading once in here that there...
6
by: Xiaozhu | last post by:
say, if you had parallel arrays containing the sales person id, the month, and the sales figures (for that person in that month), sorting on sales figure and preserve the order of figures within...
2
by: Jack | last post by:
hi all I would find a parallel sorting algorithms written with pthread programs, as a benchmark to run. Any pointing will be of help thankyou in advance
23
by: yatindran | last post by:
hai this is my 2d array. int a = { {5,2,20,1,30,10}, {23,15,7,9,11,3}, {40,50,34,24,14,4}, {9,10,11,12,13,14}, {31,4,18,8,27,17}, {44,32,13,19,41,19}, {1,2,3,4,5,6},
38
by: ssg31415926 | last post by:
I need to compare two string arrays defined as string such that the two arrays are equal if the contents of the two are the same, where order doesn't matter and every element must be unique. ...
1
by: kmuz08 | last post by:
Hello to everyone, I have to do a project in my discovering programming class based on creating parallel arrays for an order form. I am still not completely sure was a parallel array...
3
by: SneakyElf | last post by:
i am very green with c++ so i get stuck on very simple things anyway, i need to write a program that would read data from file (containing names of tv shows and their networks) one line at a time...
4
by: mh | last post by:
I want to interate over two arrays in parallel, something like this: a= b= for i,j in a,b: print i,j where i,j would be 1,4, 2,5, 3,6 etc.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.