473,385 Members | 1,343 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,385 software developers and data experts.

C++ ARRAY HELP!!

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

Sep 14 '05 #1
1 2324
* ae******@gmail.com:
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?
Sep 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JackM | last post by:
Let me attempt to explain my problem. I have a crude php script that takes a text list of songs that was generated by an mp3 list program and translates each entry into the form where they can be...
5
by: ali | last post by:
Hi, I'm trying to understand the reason for different output on the following codes Code1: #include <iostream.h> int main()
1
by: aemazing | last post by:
i've been tryin 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...
5
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as...
3
by: d4m | last post by:
I have the following which works okay... Dim arrayTable As Variant Dim varTable As Variant arrayTable = Array("SG", "Oakland", "Server") For Each varTable In arrayTable SQL1 = "INSERT...
3
by: clawton | last post by:
Hi All - I've got a 3rd party COM object that returns an array of bytes that are a TIFF image. After adding the reference to the com object to my solution the C# signature for the method is...
3
by: kurrent | last post by:
i'm still new to php and programming and was hoping to get some help on a few questions i haven't had success in answering myself. I successfully created my first very simple script to accomplish a...
5
by: Stephen3776 | last post by:
I am doing an inventory control progam and trying to output a multiple array, I am getting an illegal conversion error java.lang.double !d. Can somebody tell me what I am doing wrong or if there is...
1
by: comedydave | last post by:
Hi guys, I'm new to ASP and need some array help. I need to have a shopping cart. When you visit the site it creates a session and an array. When you click add to basket it adds the item ID to...
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...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.