Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ ARRAY HELP!!

Reply
Thread Tools

C++ ARRAY HELP!!

 
 
aemazing@gmail.com
Guest
Posts: n/a
 
      09-14-2005
hello, im new to the forum and i wanted to help with my c++ program.
the teacher wants us to design a progrm that would keep track of
airplanes awaitin landing at an airport. the program will maintain a
queue of flights numbers.

the program will be abel to do the following:

Add a new flight number to the end of the queue (got it done)
LAnd the plane at the front of the queue - problems wit it-
display the queue - got it done
seach for a specific flight number in queue ( didn't get there yet)
move a flight number one one position in the queue to another ( didn't
get there yet)

this is what i have so far. it runs but something is wrong and i don't
know what it is.

#include <iostream>
#include <iomanip>
using namespace std ;

const int MAXQUEUE = 100 ; // maximum number of flights in the queue

void displayQueue (int[], int) ;
void getChoice ();
void addPlane (int[], int&) ;
int checkPlane (int[], int, int) ;

int main ()
{
int queue[MAXQUEUE] ; // array of incoming flight numbers
int qsize = 0 ; // number of flights in the queue
char choice; // user's choice of next operation

do
{ // start menu loop
displayQueue (queue, qsize) ;
getChoice();
switch (choice)
{ // start switch
case 'S' : cout << "under construction" << endl; break ;
case 'L' : cout << "under construction" << endl; break ;
case 'A' : addPlane (queue, qsize) ; break ;
case 'M' : cout << "under construction" << endl; break ;
case 'Q' : cout << "program ended" << endl ;
} // end switch
} while (choice != 'Q'); // end menu loop

return 1 ;
}

//============displayQueue=====================
// task - display the position and flight number of each flight in the
array
// pre - given an array of flight numbers and number of flights in the
array
// post - nothing

void displayQueue (int list[], int lsize)
{ // start function
int w ;
cout << endl << endl << endl ;
if (lsize == 0)
cout << "no flights awaiting landing at this time" << endl ;
else
{ // start listing
cout << "Queue size = " << lsize << endl << endl ;
cout << "Position Flight#" << endl ;
for (w = 0; w < lsize; w++)
cout << setw(5) << w + 1 << setw(12) << list[w] << endl ;
} // end listing
} // end function

//============getChoice========================
// task - obtain a choice code from the user
// pre - nothing
// post - a valid, uppercase code is returned

void getChoice()
{ // start function
char holdCode;
char pick;


if(pick == holdCode)
{
cout << endl << " to search for a flight number, enter S" ;
cout << endl << " to add a flight to the queue, enter A" ;
cout << endl << " to land the next flight, enter L" ;
cout << endl << " to move a flight in the queue, enter M" ;
cout << endl << " to quit the program, enter Q" ;
cout << endl << " enter your choice " ;
cin >> holdCode ;
}
else
{
cout << " not a valid choice "<<endl;
}
holdCode = toupper(holdCode) ; // convert to upper case
} // end function


//======================addPlane==================== =======
// task - add a new flight to the queue
// pre - given an array of flight numbers and number of flights in
array
// post - size of array is increased, new flight number added to end

void addPlane (int list[], int& lsize)
{ // start function
int newFlight ; // flight number to be added to queue
int w;
char pause ;
cout << endl << "Enter flight number to add : " ;
cin >> newFlight;



if (lsize == MAXQUEUE)
{ // start queue is full
cout << endl << "EMERGENCY! queue is full, cannot add flight" <<
newFlight ;
cout << endl << "press any key to continue" ;
cin.get(pause) ;
return ;
} // end queue is full
//list[lsize] = newFlight ; // add flight to end of list
lsize++ ; // increase list size

for (w = 0; w < lsize; w++)
if (newFlight == list[w])
return ;
} // end function


//=====================checkPlane=================== ==========
// task - search the list of flights for a given flight number
// pre - given an array of flight numbers, number in array, and target
flight
// post - return queue position if target is found in array, else
return -1

int checkPlane (int list[], int lsize, int target)
{ // start function
int w ;
for (w = 0; w < lsize; w++)
if (target == list[w])
return w + 1;
return -1 ;
} // end function




any help would be appreciated. thanks-

Joyce

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      09-14-2005
* http://www.velocityreviews.com/forums/(E-Mail Removed):
> hello, im new to the forum


Instead of using Google's web based interface, consider using a newsreader
(client for usenet): it's much better.


> the teacher wants us to design a progrm that would keep track of
> airplanes awaitin landing at an airport. the program will maintain a
> queue of flights numbers.
>
> the program will be abel to do the following:
>
> Add a new flight number to the end of the queue (got it done)
> LAnd the plane at the front of the queue - problems wit it-
> display the queue - got it done
> seach for a specific flight number in queue ( didn't get there yet)
> move a flight number one one position in the queue to another ( didn't
> get there yet)
>
> this is what i have so far. it runs but something is wrong and i don't
> know what it is.


You should describe what you expect, and what you actually get.



> #include <iostream>
> #include <iomanip>
> using namespace std ;
>
> const int MAXQUEUE = 100 ; // maximum number of flights in the queue


Don't use all uppercase except for macros, where you should always.


> void displayQueue (int[], int) ;
> void getChoice ();
> void addPlane (int[], int&) ;
> int checkPlane (int[], int, int) ;


Don't use raw arrays. Use e.g. std::vector.



> int main ()
> {
> int queue[MAXQUEUE] ; // array of incoming flight numbers
> int qsize = 0 ; // number of flights in the queue
> char choice; // user's choice of next operation
>
> do
> { // start menu loop
> displayQueue (queue, qsize) ;
> getChoice();
> switch (choice)
> { // start switch
> case 'S' : cout << "under construction" << endl; break ;
> case 'L' : cout << "under construction" << endl; break ;
> case 'A' : addPlane (queue, qsize) ; break ;
> case 'M' : cout << "under construction" << endl; break ;
> case 'Q' : cout << "program ended" << endl ;
> } // end switch
> } while (choice != 'Q'); // end menu loop
>
> return 1 ;
> }


Indentation. It may be that Google f*cks this up. Try a newsreader instead
of Google's web-based interface.



> //============displayQueue=====================
> // task - display the position and flight number of each flight in the
> array
> // pre - given an array of flight numbers and number of flights in the
> array
> // post - nothing
>
> void displayQueue (int list[], int lsize)
> { // start function
> int w ;
> cout << endl << endl << endl ;
> if (lsize == 0)
> cout << "no flights awaiting landing at this time" << endl ;
> else
> { // start listing
> cout << "Queue size = " << lsize << endl << endl ;
> cout << "Position Flight#" << endl ;
> for (w = 0; w < lsize; w++)
> cout << setw(5) << w + 1 << setw(12) << list[w] << endl ;
> } // end listing
> } // end function





> //============getChoice========================
> // task - obtain a choice code from the user
> // pre - nothing
> // post - a valid, uppercase code is returned


Oops, a void function doesn't return anything.


> void getChoice()
> { // start function
> char holdCode;
> char pick;
>
>
> if(pick == holdCode)


Oops, uninitialized.

Now just correct those two errors, and possibly the indentation, and proceed
to the next error, and so on.

But you're strongly adviced to use std::vector, not a raw array.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM
How to combine 2 int Array into ONE int Array ? S300 Java 4 08-19-2003 07:04 PM
hashed array in array need the keys... and length Daniel Perl 1 08-14-2003 06:49 PM



Advertisments