Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,234 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,684 people online right now. Registration is fast and FREE... Join Now!




beginners for arrays help! please

 
Reply to this topicStart new topic

beginners for arrays help! please, air line reservation

varon
15 Mar, 2007 - 05:55 PM
Post #1

New D.I.C Head
*

Joined: 22 Feb, 2007
Posts: 22


My Contributions
hi all i m beginner to c++ and thus find very hard copin with arrays....
heres my question from the assignmnet.. hmmm i am kind a lost and i dont no wut to do ....could anyone tell me what to do !!!!
seeking immediate help!!


heres is my question
A small airline has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats).

Your program should display the following menu of alternatives -Please type 1 for "First class" and Please type 2 for "Economy". If the person types 1, your program should assign a seat in the first class section (seats 1-5). If the person types 2, your program should assign a seat in the economy section (seats 6-10). If the user enters a different number then return an error message and prompt the user to enter another number. Your program should print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane. Your program should of course never assign a seat that has been assigned. Use an array to represent the seating chart of the plane. The seats are available if the corresponding position in the array has the value 0. Set the position to 1 to indicate that the corresponding seat has been assigned.




heres my code (screwed up tho!!)
CODE
#include<iostream>
#include<iomanip>
using namespace std;

void  first_class(int[],int);
//void int econ_class(int[],int);
int main()
{
    const int max_size=5;
    int first[max_size]={0,0,0,0,0};
    //int economy[max_size]={0,0,0,0,0};
    int value,size=0;
    

    cout<<"please enter 1 for first class and 2 for econcomy class"<<endl;
    cin>>value;

    if (value==1){
        first_class(first,max_size);
        cout<<"thr things ar"<<endl;
        for (int i=0;i<max_size;i++)
            cout<<first[i]<<endl;
    }

        if ((value!=1)&&(value!=2))
    cout<<"error"<<endl;
        //if (size==max_size)
        //cout<<"sorry! seats already full"<<endl;
    


        return 0;
    }

void first_class(int b[],int max_size)
{
    for (int k=0;k<max_size;k++)
        b[k]=5;
    
    
}

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Beginners For Arrays Help! Please
15 Mar, 2007 - 06:31 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Too funny, I did this same assignment in my C programming class.

First thing is you only need one array for both types of seating. You need to declare an array that has 10 elements. Elements 0 - 4 are First Class and elements 5 - 9 are Economy class.

You are on the right track. You will need a function for each type of seating that will check for availability of a seat and assign the seat until they are all full.

Beyond that, what specific problems are you having?
User is online!Profile CardPM
+Quote Post

varon
RE: Beginners For Arrays Help! Please
15 Mar, 2007 - 06:43 PM
Post #3

New D.I.C Head
*

Joined: 22 Feb, 2007
Posts: 22


My Contributions
hey
ur mean that i have to use only one array (which is for both first and economy class)

const int max_size=10;
int seating[max_size]={0,0,0,0,0,0,0,0,0,0};
i got this part but i want to know if calling a function in arrays is same like in normal, and how do i assign value 1 if the seat is filled and if i have to use the expression(showing filled seat status) in main function or the respective caller function .
plz that wld be really helpful





QUOTE(jayman9 @ 15 Mar, 2007 - 07:31 PM) *

Too funny, I did this same assignment in my C programming class.

First thing is you only need one array for both types of seating. You need to declare an array that has 10 elements. Elements 0 - 4 are First Class and elements 5 - 9 are Economy class.

You are on the right track. You will need a function for each type of seating that will check for availability of a seat and assign the seat until they are all full.

Beyond that, what specific problems are you having?


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:56PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month