473,782 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Parallel Arrays - Storing and Sorting

5 New Member
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 5263
Ganon11
3,652 Recognized Expert Specialist
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
earla12
5 New Member
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
earla12
5 New Member
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 Recognized Expert Specialist
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 Top Contributor
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
earla12
5 New Member
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 Recognized Expert Specialist
It's always something simple :)

Good to see you figured it out!
Mar 13 '07 #8
earla12
5 New Member
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
1423
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 store some information in some session variables. But this information is coming from an old dbase system. In the beginning of this project it was just a simple static array of information. Afterwards it turns out that this must be a dynamic array...
9
2624
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 is a maximum value the operator has to accept. Since the programm should accept almost any number of integers, I am not sure if this limit will be enough. Also I would like to know the same about the STL-Vector class, since I haven't decided...
6
3532
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 the data about the same person: Original Data: id month sales +-----+ +-----+ +-----+ | 432 | | 8 | | 89 | +-----+ +-----+ +-----+ | 123 | | 8 | | 116 |
2
3241
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
6353
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
10179
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. E.g. these two arrays would test as equal: servers = "Admin" servers = "Finance" servers = "Payroll" servers = "Sales"
1
1806
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 is! But basically any help, tips, pr tricks would help. My program is to allow the user to enter the name of a product, the product number or serial number, the quantity, and the cost per item and have them all displayed in different parrallel...
3
2193
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 ( ; separates tv show and network) sort the strings according to the network and according to the show. and so: //to open file - ifstream myFile;
4
2983
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
9479
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10311
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8967
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7492
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6733
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.