int main()
{
	
	
	//declare variables
	struct name names[16];
	int chooseFirst[7]={0}; //seats in first class
	int choosePreferred[5]={0}; //seats in preferred
	int chooseEconomy[7]={0}; //seats in economy
	float mealCost, ticketPrice;
	int seatClass, seatNum, counter, j=1000, yesNo;
	char addTicket, mealChoice;
	char passName[50] = {""};

	system("color 0b");

    //airplane graphic
	for (counter=0; counter < 50; counter++){
	printf("\t");
    flyPlane();
    for (counter=0; counter < 50; counter++) {
        usleep(j);
        j = (int)(j * 0.9);
        printf("\t");
    	}
	}	
	printf("Thank you for booking your flight with Code Flight Airlines.\n");
	printf("\n");

	//function called to run program
	getTicket (seatClass, seatNum, chooseFirst, choosePreferred, chooseEconomy, mealChoice, names, addTicket);
	system("Pause");
    return 0;
}
Ejemplo n.º 2
0
void Lock::GlobalLock::_enqueue(LockMode lockMode, Date_t deadline) {
    if (lockMode == LockMode::MODE_IX) {
        auto ticketholder = FlowControlTicketholder::get(_opCtx);
        if (ticketholder) {
            ticketholder->getTicket(_opCtx);
        }
    }

    try {
        if (_opCtx->lockState()->shouldConflictWithSecondaryBatchApplication()) {
            _pbwm.lock(MODE_IS);
        }
        auto unlockPBWM = makeGuard([this] {
            if (_opCtx->lockState()->shouldConflictWithSecondaryBatchApplication()) {
                _pbwm.unlock();
            }
        });

        _opCtx->lockState()->lock(
            _opCtx, resourceIdReplicationStateTransitionLock, MODE_IX, deadline);

        auto unlockRSTL = makeGuard(
            [this] { _opCtx->lockState()->unlock(resourceIdReplicationStateTransitionLock); });

        _result = LOCK_INVALID;
        _result = _opCtx->lockState()->lockGlobalBegin(_opCtx, lockMode, deadline);

        unlockRSTL.dismiss();
        unlockPBWM.dismiss();
    } catch (const ExceptionForCat<ErrorCategory::Interruption>&) {
        // The kLeaveUnlocked behavior suppresses this exception.
        if (_interruptBehavior == InterruptBehavior::kThrow)
            throw;
    }
}
Ejemplo n.º 3
0
void Ticket::saveToFile()
{
    string fileName = "ticket_" + ticketID + ".txt";

    ofstream myFile;
    myFile.open(fileName);

    myFile << getTicket();

    myFile.close();
}
Ejemplo n.º 4
0
bool OTicketDAO::verwijderTicket(int id)
{
	Ticket* temp = getTicket(id);
	if(temp == 0)
	{
		return false;
	}
	tickets.erase(tickets.begin()+getPositie(id));
	delete temp;
	return true;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[]){
	init();
	_listen();
	char ticketMessage[32];
	char read_buf[MAXBUF];
	int i;
	int sfd;
	for(;;){
		refreshSelect();
		int maxfd = getMaxFD();
		bool isClient = true;
		if (select(maxfd+1,&read_fd,NULL,NULL,NULL)){
			for(i=0;i<CLI_FD;i++){
				if(FD_ISSET(g_sfd[i],&read_fd)){
					sfd = g_sfd[i];
					break;
				}
				if(FD_ISSET(service_sfd[i],&read_fd)){
					service_(service_sfd[i]);
					isClient = false;
					break;
				}
			}
		}
		if(isClient){
			clilen[i] = sizeof(clients[i]);
			int nsfd = accept(sfd,(struct sockaddr *) &clients[i], &clilen[i]);
			char *buf;
			bzero(ticketMessage, 32);
			bzero(read_buf,MAXBUF);
			//strcpy(buf,"Which mall do you want to connect to?");
			buf = "Which mall do you want to connect to?";
			int len = strlen(buf);
			send(nsfd, buf, len, 0);

			int n;
			n = recv(nsfd,read_buf,MAXBUF,0);
			printf("The client wants to connect to - %s\n",read_buf);

			int ticket = getTicket();
			sprintf(ticketMessage, "%d:%d ", PORT_C, ticket);
			send(nsfd, ticketMessage, strlen(ticketMessage), 0);
			close(nsfd);
		}	
	}
}
Ejemplo n.º 6
0
Ticket* OTicketDAO::bewaarTicket(Ticket* ticket)
{
	if(ticket->getTicketID() == -1)
	{
		//Dit is een nieuw adres en simuleert de toekenning van een sequentiële ID door de database
		Ticket* temp = tickets.at(tickets.size()-1);
		int nieuweID = temp->getTicketID()+1;
		ticket->setTicketID(nieuweID);
	}
	Ticket* temp = getTicket(ticket->getTicketID());
	if(temp == 0)
	{
		tickets.push_back(ticket);
		return ticket;
	}
	else
	{
		//Ticket updaten
		temp->setTicketID(ticket->getTicketID());
		return temp;
	}

	return 0;
}
//function created to allow user to reserve seat on plane
void getTicket(int seatClass, int seatNum, int chooseFirst[], int choosePreferred[], int chooseEconomy[], char mealChoice, struct name names[], char addTicket){
	
	//declare variables in function
	int counter = 1, yesNo;
	
	//user inputs 1,2,3 to select seat class on plane
	printf("\nPlease select the class you'd like to be seated in\n");
	printf("First = 1, Preferred = 2, Economy = 3: ");

	fflush(stdin);
	scanf("%d", &seatClass);
	//output displays graphic of seats on plane depending on which class was selected
		if (seatClass == 1){
			drawFirstClass(chooseFirst);
		}
			else if (seatClass == 2){
				drawPreferred(choosePreferred);
			}
				else {
				drawEconomy(chooseEconomy);
				}

	//output confirms choice and checks for available seats.
	//if no available seats are in the section, user can select from another class
	if (seatClass == 1) {
		printf("You have selected a seat in First Class.\n");
		seatNum=checkSeats(seatClass, chooseFirst, choosePreferred, chooseEconomy);
			if (seatNum == -1) {
				printf("Sorry, First class is full. Would you like to choose another class (y/n)? ");
				scanf("%d", &yesNo);
					if(yesNo == 'y'){ 
						getTicket(seatClass, seatNum, chooseFirst, choosePreferred, chooseEconomy, mealChoice, names, addTicket);	
					} else { 
						printf("\n\nThe next flight leaves in 3 hours."); 
						system("pause");
						return;	
					}
			}	
	} else if (seatClass == 2) {
		printf("\nYou have selected a seat in Preferred.\n");
		seatNum=checkSeats(seatClass, chooseFirst, choosePreferred, chooseEconomy);
			if (seatNum == -1) {
				printf("Sorry, Preferred class is full. Would you like to choose another class (y/n)? ");
				scanf("%d", &yesNo);
					if(yesNo == 'y'){ 
						getTicket (seatClass, seatNum, chooseFirst, choosePreferred, chooseEconomy, mealChoice, names, addTicket);	
					} else { 
						printf("\n\nThe next flight leaves in 3 hours."); 
						system("pause"); 
						return; 
					}			
			}
	} else {
		printf("\nYou have selected a seat in Economy.\n");
		seatNum=checkSeats(seatClass, chooseFirst, choosePreferred, chooseEconomy);
			if (seatNum == -1) {
				printf("Sorry, Economy class is full. Would you like to choose another class (y/n)? ");
				scanf("%d", &yesNo);
					if(yesNo == 'y'){ 
						getTicket (seatClass, seatNum, chooseFirst, choosePreferred, chooseEconomy, mealChoice, names, addTicket);
					} else {
						printf("\n\nThe next flight leaves in 3 hours."); 
						system("pause"); 
						return; 
					}
			}
	}
		
	//user has option to add a meal plan to their ticket for an additional $10
	printf("\n");
	printf("Would you like to add a $10 meal plan to your ticket (y/n)? ");
	fflush(stdin);
	scanf("%c", &mealChoice);
	//output lets user know the cost will be added to their ticket, if they choose no, they can proceed to booking their ticket
	if (mealChoice == 'y'){
		printf("\nThe meal plan will be added to your ticket. \n\n");
	}
	else{
		printf("\nThank you. Please proceed to booking your ticket. \n\n");
	}

	//user inputs passenger's name
	printf("What is the name of the passenger (first and last)? ");
	scanf("%s", names[counter].fullName);

	//user has the option to book another ticket
	printf("\nDo you want to book another ticket (y/n)? ");
	fflush(stdin);
	scanf("%c", &addTicket);
	
	counter++;
	//function is called to book additional tickets
	if (addTicket == 'y'){
	getTicket (seatClass, seatNum, chooseFirst, choosePreferred, chooseEconomy, mealChoice, names, addTicket);
	}
		//boarding pass prints to show Passenger Name, Seat Class, Seat Number, if a meal plan was selected, and Ticket Price
		else{
		printf("\n**Boarding Pass** \n");
		printf("Enjoy your flight! \n\n");
		
		//output shows passenger's name
		printf("Passenger Name: %s \n", names[counter].fullName);
		
		//output shows seat class selected
		if (seatClass == 1){
			printf("Seat Class: First Class \n");
		}
		else if (seatClass == 2){
			printf("Seat Class: Preferred \n");
		}
		else{
			printf("Seat Class: Economy \n");
		}
	}
		// output shows seat number based on available seats
		printf("Seat Number: %d \n", seatNum);
			
		//output shows if meal plan was selected
		printf("Meal Plan? %s \n", mealChoice == 'n' ? "No" : "Yes");
		
		//output shows ticket price	
		if (mealChoice == 'y' && seatClass == 1){
			printf("Ticket Price: $510.00 \n");
		}
		else if (mealChoice == 'y' && seatClass == 2){
			printf("Ticket Price: $360.00 \n");			
		}
		else if (mealChoice == 'y' && seatClass == 3){
			printf("Ticket Price: $210.00 \n");			
		}
		else if (mealChoice == 'n' && seatClass == 1){
			printf("Ticket Price: $500.00\n");
		}
		else if (mealChoice == 'n' && seatClass == 2){
			printf("Ticket Price: $350.00 \n");			
		}
		else if (mealChoice == 'n' && seatClass == 3){
			printf("Ticket Price: $200.00 \n");			
		}
		
		printf("-------------------------------\n");		
	
}