void arrivals()		// this model segment spawns departing customers
{
	create("arrivals");

	while(clock < 1440.)	//
	{
		hold(expntl(10)); // exponential interarrivals, mean 10 minutes
        if(newCustomer()){ // see if customer balks after looking at line
			arr_cust();	// new customer enters line
        }
    }
}
Example #2
0
int main(int argc, char* argv[])
{
    if(argc != 2) // Test for the right number of command-line arguments
    { // If the count is wrong, print a usage mesage instead.
        printf("%s requires ONE command-line argument\n", argv[0]);
        printf("(the number of customers per seller).\n");
        return 0;
    }
    
    srand(time(0));
    setConcert(newConcert());
    
    // Convert the number of customers passed to the program to an
    // int for later use
    const int NUMBER_OF_CUSTOMERS = atoi(argv[1]);
    
    printf("Proceeding with %d customers per seller.\n", NUMBER_OF_CUSTOMERS);
    
    // Create the sellers so that there will be lines to go to
    int i;
    pthread_t sellerThread[HIGH_SELLERS + MID_SELLERS + LOW_SELLERS];
    for(i = 0; i < HIGH_SELLERS; i++) {
        sellerThread[i] = *newSeller('H', i);
    }
    for(i = 0; i < MID_SELLERS; i++) {
        sellerThread[HIGH_SELLERS + i] = *newSeller('M', i);
    }
    for(i = 0; i < LOW_SELLERS; i++) {
        sellerThread[HIGH_SELLERS + MID_SELLERS + i] = *newSeller('L', i);
    }

    // Create customers to go to the lines
    initializeCustomerQueues(NUMBER_OF_CUSTOMERS);
    for(i = 0; i < HIGH_SELLERS + MID_SELLERS + LOW_SELLERS; i++) {
        int j;
        for(j = 0; j < NUMBER_OF_CUSTOMERS; j++) {
            newCustomer(i);
        }
    }
    
    do {          // Loop to ensure that the program doesn't terminate before
        sleep(1); // all seats have been assigned
        char event[99];
        sprintf(event, "%3d tickets remain.", (*getConcert()).tickets);
        printEvent(event);
    } while(!isFinished(getConcert()));
    for(i = 0; i < HIGH_SELLERS + MID_SELLERS + LOW_SELLERS; i++) {
        pthread_join(sellerThread[i], NULL);
    }
    printConcert(getConcert());
    
    return 0;
}
Example #3
0
/*
 * Method to process main menu
 *
 * Daniel Lennart
 */
void handleMainMenu(int opt){
    if(opt == 1){

        Order order = { 0 };
        order.customer  = newCustomer();
        order.date      = getDate();

        int id;
        do {
            id = printProductMenu();
            if (id > 0 && id < 8) {
                order.product[order.products_count] = products[id-1];
                order.products_count++;
                printf("Added product to queue\n");

                if (order.products_count == n) id = 8;

            } else if (id != 8) {
                printf("Incorrect Option");
            }
        } while (id != 8);

        addToQueue(order);
    }
    else if(opt == 2){
        printf("Process orders\n");
        int next_opt = printStaffMenu();
        handleProcessMenu(next_opt);

    }
    else if (opt == 3){
        printf("Thank you for using the program, bye!\n");
        exit(0);
    }
    else{
        printf("Invalid option!\n");
    }
}
int qArrive(Queue *q, productList *products)
{
    int code, quantity;
    char id[10];
    char input;
    Customer *c = newCustomer();
    Product *p;
    basketItem *item;
    
    printf("\n\tEnter customer id:\n\t");
    scanf("%s", id);   
    customerInit(c, id);
    
    clearScreen();

    do
    {
                    clearScreen();
                    
                    printf("\n\tAdd items to bill of '%s'\n", id);
                    
                    printf("\n\t\tEnter product code: \t(0: quit)\n\t\t");
                    scanf("%d", &code);
                    
                    if(code==0)
                               break;
                    
                    p=findProductByCode(code, products);
                    
                    if(p==NULL)
                    {
                               printf("Error: Cannot add item to basket.");
                               wait();
                               continue;
                    }
                    
                    printf("\n\t\tEnter quantity:\n\t\t");
                    scanf("%d", &quantity);
                    
                    
                    
                    addToBasket(c, newBasketItem(p, quantity));
                    
                    printf("\n\t\t%d of %s were added to the basket.", quantity, getProductName(p));
                    printf("\n\n\t\t[backspace: undo  0: done  1: continue]\n\t\t");
                    input = getch();
                    
                    if(input=='\b')
                    {
                                remFromBasket(c);
                                printf("\n\t\tLast item was removed successfully!");
                                wait();
                                continue;
                    }
                    
                    
                    
    }while(input!='0');
    
    queueInsert(q, c);
}
Example #5
0
int main(int argc, char *argv[]) {
	
	// erstelle irgendwelche rabatte
	int i, i1;	
	for(i = 0; i < x; i++) {
		for(i1 = 0; i1 < y; i1++) {
			discounts[i][i1] = rand() % 100;
		}
	}
	
	

	while(option != 3) {

		printf("\nOptionen:\n");
		printf("1: Neue Produkte eingeben\n");
		printf("2: Neue Kunden eingeben\n");
		printf("3: Beenden\n\n");

		printf("Weitere Optionen\n");
		printf("4:  Alle Produkte auflisten\n");
		printf("5:  Alle Personen auflisten\n");
		printf("6:  Alle Aufträge auflisten\n");
		printf("7:  Neuen Auftrag anlegen\n");
		printf("8:  Auftrag bearbeiten\n");
		printf("9:  Auftrag löschen\n");
		printf("10: Person bearbeiten\n");
		printf("11: Produkt bearbeiten\n");
		printf("12: Nach Produkt suchen\n");
		printf("13: Nach Kunde suchen\n");
		printf("14. Rekusiver Warenwert\n");
		printf("15. Iterativer Warenwert\n");
		printf("16. Rabattliste");
		
		printf("\nAuswahl: ");
		scanf("%i", &option);
		Order o;
		Product p;
		Customer c;
	
		switch(option) {
			case 1:
				while(decision != 'n') {
					p = newProduct();
					getchar();
					printf("Wollen Sie noch einen Eintrag erstellen (j/n)?\n");
					scanf("%c", &decision);
					if(max_products == p.id + 1)
						resizeProductArray(&product, &max_products);
					product[p.id] = p;
					productIndex++;
				}
				decision = 'j';
			break;
			case 2:
				while(decision != 'n') {
					Customer c = newCustomer();
					getchar();
					printf("Wollen Sie noch einen Eintrag erstellen (j/n)?\n");
					scanf("%c", &decision);	
					if(max_customer == c.id + 1)
						resizeCustomerArray(&customer, &max_customer);
					customer[c.id] = c;
					customerIndex++;
				}
				decision = 'j';
			break;
			case 3: 
				printf("\nBeendet..\n");
			break;
			case 4:
				printProducts(product, productIndex);
			break;
			case 5:
				printCustomer(customer, customerIndex);
			break;
			case 6:
				printOrders(order, orderIndex);
			break;
			case 7:
				o = newOrder();
				if(max_order == c.id + 1)
					resizeOrderArray(&order, &max_order);
				order[o.id] = o;
				orderIndex++;
			break;
			case 8:
				// auftrag bearbeiten
			break;
			case 9:
				// auftrag loeschen
			break;
			case 10:
				c = searchCustomer(customer, customerIndex);
				c = editCustomer(c);
				customer[c.id] = c;
			break;
			case 11:
				p = searchProduct(product, productIndex);
				p = editProduct(p);
				product[p.id] = p;
			break;
			case 12:
				p = searchProduct(product, productIndex);
				printf("\nArtikelnummer: %i\n", p.id+1);
				printf("Artikelname: %s\n", p.name);
				printf("Artikelpreis: %0.2f\n", p.price);
				printf("Lagerbestand: %i\n", p.amount);
			break;
			case 13:
				c = searchCustomer(customer, customerIndex);
				printf("\nKundennummer: %i\n", c.id);
				printf("Kundenname: %s\n", c.name);
			break;
			case 14: 
				printf("\nAktueller Warenwert: ");
				printf("%0.2f Euro (rekursiv)\n", recursiveProductValue(product, productIndex-1));
			break;
			case 15: 
				printf("\nAktueller Warenwert: ");
				printf("%0.2f Euro (iterativ)\n", iterativeProductValue(product, productIndex-1));
			break;
			case 16:
					printf("Produkt/Anzahl");
					for(i = 0; i < x; i++) {
						for(i1 = 0; i1 < y; i1++) {
							printf("[%02i]", discounts[i][i1]);
						}
						printf("\n");
					}
			break;
			default: break;
		}
	}
}
Example #6
0
void doSomeStuff(){
    printf("Creating account for Dan Brown\n");
    struct Writer danBrown = newWriter(
        "Dan Brown",
        "danbrown",
        "password"
    );
    addWriter(&danBrown, &eBookStore);
    printf("Created account for Dan Brown with ID %d\n\n", danBrown.id);

    printf("Adding the book Angels and Demons\n");
    struct Book angelsAndDemons = newBook(
        "Angels and Demons",
        "Dan Brown",
        "Science and Mythology and Stuff",
        "In not so distant past...",
        danBrown.id,
        100
    );
    publishBook(&angelsAndDemons, &eBookStore);
    printf("Added the book Angels and Demons with ID %d\n\n", angelsAndDemons.id);

    printf("Adding the book Da Vinci Code\n");
    struct Book daVinciCode = newBook(
        "Da Vinci Code",
        "Dan Brown",
        "Its about the hipster Leo",
        "Once upon a time...",
        danBrown.id,
        100
    );
    publishBook(&daVinciCode, &eBookStore);
    printf("Added the book Da Vinci Code with ID %d\n\n", daVinciCode.id);

    printf("Books published by %s on our platform are,\n", danBrown.name);
    for(int i=0;i<danBrown.bookCount;i++){
        int bookID = danBrown.bookIDs[i];
        struct Book *b = eBookStore.bookDataStore.books[bookID];
        printf("#%d:\t%s\n", i+1, b->title);
    }
    printf("\n");

    printf("Finding books similar to %s\n", daVinciCode.title);
    assignSimilarBooks(&daVinciCode, &eBookStore);
    for(int i=0;i<daVinciCode.similarBookCount;i++){
        int bookID = daVinciCode.similarBooks[i];
        struct Book *b = eBookStore.bookDataStore.books[bookID];
        printf("#%d:\t%s\n", i+1, b->title);
    }
    printf("\n");

    printf("Creating customer account for Robert Langdon\n");
    struct Customer robertLangdon = newCustomer("robertlangdon", "password");
    addCustomerToDataStore(&robertLangdon, &eBookStore.customerDataStore);
    printf("Created customer account for Robert Langdon with user id %d\n\n", robertLangdon.id);

    printf("Searching for books with the title 'Angels and Demons'\n");
    struct Book* searchResult = searchBooksInDataStore(1, "Angels and Demons", 1, &eBookStore.bookDataStore)[0];
    printf("Found one book with the name %s by the author %s\n", searchResult->title, searchResult->author);
    printf("Its summary is, %s\n\n", searchResult->summary);

    printf("Submitting an excellent review for %s from user name %s\n", searchResult->title, robertLangdon.username);
    addReview(searchResult, &robertLangdon, 5, "Awesome read! :)", &eBookStore);
    printf("Fetching all reviews for %s,\n", searchResult->title);
    for(int i=0;i<searchResult->reviewCount;i++){
        printf("#%d: Rating: %d Comments: %s\n", i+1, searchResult->reviews[i]->rating, searchResult->reviews[i]->body);
    }
    printf("Average rating of %s is %f\n\n", searchResult->title, getAverageRating(searchResult));

    printf("That's all for this demo folks! :)\n");
}