Example #1
0
// If the user wants to sort the list he tells the program in what kind of way here.
void Information::orderSci()
{
    Service serv;
    vector<Scientist> vec;
    char number;
    cin >> number;
    cout << endl;

    switch (number) {
        case'1':{
            cout << "List sorted in alphabetical order:" << endl << endl;
            vec = serv.sortSci(number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'2':{
            cout << "List sorted in reverse alphabetical order:" << endl << endl;
            vec = serv.sortSci(number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'3':{
            cout << "List sorted ascendingly by year of birth:" << endl << endl;
            vec = serv.sortSci(number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'4':{
            cout << "List sorted descendingly by year of birth:" << endl << endl;
            vec = serv.sortSci(number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'5':{
            cout << "List sorted by gender (Female first):" << endl << endl;
            command = "SELECT * FROM Scientists ORDER BY gender, name";
            serv.sortSci(number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'6':{
            instructions();
            choices('2');
            break;}
        default:{
            cout << "This is invalid choice " << endl;
            orderSci();
            break;}
    }
}
Example #2
0
File: du.c Project: eskirk/MyDu
/*
   Prints all files in a directory and sums up total size, recursively calls sub-directories
   Printing can be turned off by passing in a non-zero value for silent
*/
void displayAll(DIR *directory, char *path, long *total, int silent, int depth, int human) {
   char *temp = malloc(sizeof(char) * MAX_LEN);
   char *curPath = malloc(sizeof(char) * MAX_LEN);
   struct dirent *tempdir = malloc(sizeof(struct dirent));
   struct stat *stats = malloc(sizeof(struct stat));

   if (directory) {
      while ((tempdir = readdir(directory)) ) {
         if (path == NULL)
            sprintf(curPath, "./%s", tempdir->d_name);
         else 
            sprintf(curPath, "%s/%s", path, tempdir->d_name);

         if (checkDir(tempdir->d_name) && strcmp(tempdir->d_name, "..") != 0 && 
          strcmp(tempdir->d_name, ".") != 0 && depth > 0 ) {
            sprintf(temp, "./%s", tempdir->d_name);
            chdir(tempdir->d_name);
            displayAll(opendir("."), curPath, total, silent, depth - 1, human);
            chdir("..");
         }
         if (strcmp(tempdir->d_name, "..") != 0 && strcmp(tempdir->d_name, ".") != 0 ) {
            lstat(tempdir->d_name, stats);
            if (!human)
               *total += roundUp((stats->st_size + (BLOCKSIZE - 1)) / BLOCKSIZE);
            if (human)
               *total += stats->st_size;
            if (!silent)
               printf("%d\t%s\n", roundUp((int)(stats->st_size + BLOCKSIZE - 1)/BLOCKSIZE), curPath);
            if (human)
               printHuman(stats, -1, curPath);
         }
      }
   }
}
Example #3
0
//Funtion for selecting ways to search for computers
void Information::searchComp()
{
    Service serv;
    vector<Computer> vec;
    char number;
    string searchStr;
    cin >> number;
    cout << endl;

    switch (number) {
        case'1':{
            cout << "Enter a Computer to search for: " << endl;
            cin.ignore();
            getline(cin,searchStr);
            cout << endl << "Search results: " << endl << endl;
            vec = serv.searchCom(searchStr, number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'2':{
            cout << "Enter a buildyear to search for: " << endl;
            cin >> searchStr;
            cout << endl << "Search results: " << endl << endl;
            vec = serv.searchCom(searchStr, number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'3':{
            cout << "Enter a type to search for: " << endl;
            cin >> searchStr;
            cout << endl << "Search results: " << endl << endl;
            vec = serv.searchCom(searchStr, number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'4':{
            compSciOrLink();
            break;}
        default:{
            cout << endl << "This is invalid choice!" << endl;
            searchSci();
            break;}
    }
}
Example #4
0
//If the user wants to search for something, he pickes the way here
void Information::searchSci()
{
    Service serv;
    vector<Scientist> vec;
    char number;
    string searchStr;
    cin >> number;
    cout << endl;

    switch (number) {
        case'1':{
            cout << "Enter a name to search for: " << endl;
            cin.ignore();
            getline(cin,searchStr);
            cout << endl << "Search results: " << endl << endl;
            vec = serv.searchSci(searchStr, number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'2':{
            cout << "Enter a year of birth to search for: " << endl;
            cin >> searchStr;
            cout << endl << "Search results: " << endl << endl;
            vec = serv.searchSci(searchStr, number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'3':{
            cout << "Enter either 'M' or 'F' to search by gender:" << endl;
            cin >> searchStr;
            cout << endl << "Search results: " << endl << endl;
            serv.searchSci(searchStr, number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'4':{
            compSciOrLink();
            break;}
        default:{
            cout << endl << "This is invalid choice!" << endl;
            searchSci();
            break;}
    }
}
Example #5
0
//Function to select different sorting of computers in output
void Information::orderComp()
{
    Service serv;
    vector<Computer> vec;
    char number;
    cin >> number;
    cout << endl;

    switch (number) {
        case'1':{
            cout << "List sorted in alphabetical order:" << endl << endl;
            vec = serv.sortCom(number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'2':{
            cout << "List sorted in reverse alphabetical order:" << endl << endl;
            vec = serv.sortCom(number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'3':{
            cout << "List sorted ascendingly by build year:" << endl << endl;
            vec = serv.sortCom(number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'4':{
            cout << "List sorted descendingly by year of birth:" << endl << endl;
            vec = serv.sortCom(number);
            displayAll(vec);
            compSciOrLink();
            break;}
        case'5':{
            instructions();
            choices('1');
            break;}
        default:{
            cout << "This is invalid choice " << endl;
            orderComp();
            break;}
    }
}
Example #6
0
/****************************** main entry *****************************/
int main()
{
	int num=5;
	int X[10]={5,4,3,2,1,0,0,0,0,0};
	int Y[10]={0,0,0,0,0,0,0,0,0,0};
	int Z[10]={0,0,0,0,0,0,0,0,0,0};
	x=X;
	y=Y;
	z=Z;

	displayAll(LENGTH,x,y,z);	//print the tower before operation
	hanoi(num,X,Y,Z);

	return 0;
}
Example #7
0
void main()
{
	int i, choice = 1;
	startNode = NULL;

	while (choice != 0)
	{
		puts("Please select an option:\n");
		puts("---------------------------------------");
		puts("01\tInsert a Node");
		puts("02\tDelete a Node");
		puts("03\tDisplay all Nodes");
		puts("04\tSearch for a Node");
		puts("\n00\tExit");
		puts("---------------------------------------\n");

		fflush(stdin);
		scanf_s("%d", &choice);

		switch (choice)
		{
		case 1:
			insertNode();
			break;

		case 2:
			deleteNode();
			break;

		case 3:
			displayAll();
			break;

		case 4:
			findNode();
			break;

		case 0:
			break;

		default:
			puts("Invalid selection!\n");
			break;
		}
	}
	free(startNode);
	free(currentNode);
}
Example #8
0
int move(int *P, int *Q)	//move the top disk of $P to $Q
{
	int i,j;
	for(i=9;P[i]==0&&i>=0;i--);
	for(j=0;Q[j]!=0&&j<10;j++);
	if(i<0||j>9)
		return 0;
	else
	{
		Q[j]=P[i];
		P[i]=0;
		displayAll(LENGTH,x,y,z);
	}

	return 0;
}
Example #9
0
void deleteNode()
{
	node *theNodeOfTheRings = NULL;//the equivalent of a previous node
	int idToFind;

	if (startNode != NULL)
	{
		currentNode = startNode;
	}
	else
	{
		puts("There are no nodes in your Linked List yet!\n");
		return;
	}

	displayAll();

	puts("Please enter the ID you wish to delete:");
	fflush(stdin);
	scanf_s("%d", &idToFind);

	if (startNode->id == idToFind)
	{
		startNode = startNode->nextNode;
		free(currentNode);
		return;
	}

	while (currentNode != NULL)
	{
		if (currentNode->id == idToFind)
		{
			theNodeOfTheRings->nextNode = currentNode->nextNode;
			free(currentNode);
			puts("Node deleted!\n");
			return;
		}
		else
		{
			theNodeOfTheRings = currentNode;
			currentNode = currentNode->nextNode;
		}
	}
	puts("The node was not found!");
}
Example #10
0
/*
Main menu interface
*/
void run(FILE *file) {
    int choice = 0;
    
    while (1) {
        displayMenu();
        choice = getChoice();
        if (choice == -2) {
            exit(0);
        } else if (choice == -1) {
            append(file);
        } else if (choice == 0) {
            displayAll(file);
        } else if (choice > 0) {
            modifyRecord(choice, file);
        } else {
            printf("\n%s\n", "Invalid choice, try again!");
        }
    } 
}
Example #11
0
File: du.c Project: eskirk/MyDu
/*
   flags:
      -a:      Displays an entry for each file in a file hierarchy
      -dn:     Goes n directories deep during recursion
      -c:      Displays a grand total
      -h:      Displays the output in a human readable way using prefixes like Byte, KB, MB...
      -f<%s>:  Tallies up only files that contain the substring s
      -v:      Displays a visual tree of the current directory
      -un:     Goes up n directories and then does what it needs to do
*/
int main(int argc, char *argv[]) {
   int all = 0, depth = 5, total = 0, human = 0, count = 1, visual = 0, look = 0, none = 0, up = 0, tdepth = 0;
   long tot = 0;
   char *find = malloc(sizeof(char) * MAX_LEN), *temp = malloc(sizeof(char) * 10), *path = malloc(sizeof(char) * MAX_LEN);
   char *rtn = malloc(sizeof(char) * MAX_LEN);
   DIR *directory = opendir(".");
   
   if (argc > 1) {
      do {
         switch(argv[count][1]) {
            case 'a':
               all = 1;
               break;
            case 'd':
               depth = atoi(&argv[count][2]);
               tdepth = depth;
               break;
            case 'h':
               human = 1;
               break;
            case 'f':
               strcpy(find, &argv[count][2]);
               look = 1;
               break;
            case 'c':
               total = 1;
               break;
            case 'v':
               visual = 1;
               break;
            case 'u':
               up = atoi(&argv[count][2]);
               break;
            default:
               none = 1;
               break;
         }
      } while (argv[++count] != NULL);
   }

   if (up) {
      if (up && look) {
         if (up > 2)
            up = 2;
      }
      goUp(up, rtn);
      directory = opendir(".");
   }

   if (none || (!all && !look && !visual)) {
      displayFolders(directory, NULL, &tot, depth, human);
      depth = tdepth;
   }

   if (all) {
      if (look) {
         printf("Look through all files on this user for substring '%s'?\ny/n: ", find);
         scanf("%s", temp);
         if (*temp == 'y' || *temp == 'Y') {
            realpath(".", path);
            chdir(getenv("HOME"));
            if (visual)
               system("tree");
            directory = opendir(".");
            findSub(directory, NULL, find);
            chdir(path);
         }
      }
      else {
         if (visual)
            system("tree");
         if (!human) {
            displayAll(directory, NULL, &tot, 0, depth, human);
            depth = tdepth;
         }

      }
   }

   if (visual && !all && !up) {
      system("tree");
   }

   if (look) {
      if (all) {
         directory = opendir(getenv("HOME"));
      }
      findSub(directory, NULL, find);
   }
   if (up) 
      chdir(rtn);

   if (total && !up) {
      tot = 0;
      directory = opendir(".");
      displayAll(directory, NULL, &tot, 1, depth, human);
      depth = tdepth;
      if (!human)
         printf("%ld\ttotal\n", tot);
      else
         printHuman(NULL, tot, "!");
   }
   else {
      tot = 0;
      directory = opendir(".");
      displayAll(directory, NULL, &tot, 1, depth, human);
   }

   if (up && visual) {
      goUp(up, rtn);
      directory = opendir(".");
      printf("%ld\t%s\n", tot, ".");
      system("tree");
   }
   else if (visual) 
      printf("%ld\t%s\n", tot, ".");

   if (!human && !visual) {
      printf("%ld\t%s\n", tot, ".");
   }

   if (human) {
      if (up) {
         if (up && look) {
            if (up > 2)
               up = 2;
         }
         goUp(up, rtn);
         directory = opendir(".");
         depth = tdepth;
         displayAll(directory, NULL, &tot, 1, depth, human);
      }
      printHuman(NULL, tot, ".");
   }

   return 0;
}
Example #12
0
int main() {
    int i, j;
    int seed = 1000;

    int numPlayer = 2;
    int p, r;
    int k[10] = {adventurer, great_hall, cutpurse, gardens, mine
               , remodel, smithy, village, sea_hag, embargo};

    int cards[10] = {copper, smithy, village, silver, mine, gold,
                gardens, remodel, embargo, cutpurse};

    struct gameState G, testG;
    int index, count;
    int treasureCount;
    int treasureDrawn, otherRevealed;
    int preDeck, preDiscard, preHand;
    bool pass = true;

    memset(&G, 23, sizeof(struct gameState));   // clear the game state
    r = initializeGame(numPlayer, k, seed, &G); // initialize a new game

    printf("----------------- Testing adventurer\n");

    // Number of runs
    for (j = 1; j < 1001; j++) {
        // Copy the game state to a test case
        memcpy(&testG, &G, sizeof(struct gameState));

        // Player 0
        p = 0;
        printf("----------------- Random Deck Test %d\n", j);
        printf("----------------- Initial counts\n");

        // Initialize deckCount and treasureCount
        testG.deckCount[p] = 0;
        treasureCount = 0;

        // Create deck of 10 random cards
        for (i = 0; i < 10; i++) {
            index = floor(Random() * 10);
            testG.deck[p][i] = cards[index];
            testG.deckCount[p]++;
        }

        // Check deck for number of treasures
        for (i = 0; i < testG.deckCount[p]; i++) {
            if (testG.deck[p][i] == copper || testG.deck[p][i] == silver || testG.deck[p][i] == gold) {
                treasureCount++;
            }
        }

        // Discard should be empty
        testG.discardCount[p] = 0;

        // Create fixed hand of 5 cards
        testG.handCount[p] = 0;
        for (i = 0; i < 5; i++) {
            testG.hand[p][i] = estate;
            testG.handCount[p]++;
        }

        // Save pre-test values
        preDeck = testG.deckCount[p];
        preDiscard = testG.discardCount[p];
        preHand = testG.handCount[p];

        // Calculate expected values
        // If no treasures in deck, then reveal all cards in deck
        if (treasureCount == 0) {
            treasureDrawn = 0;
            otherRevealed = testG.deckCount[p];
        }
        // If 1 treasure in deck,
        // then reveal all cards in deck in an attempt to get 2 treasures
        else if (treasureCount == 1) {
            treasureDrawn = 1;
            otherRevealed = testG.deckCount[p] - treasureDrawn;
        }
        // If at least 2 treasures in deck
        else {
            treasureDrawn = 0;
            otherRevealed = 0;
            i = testG.deckCount[p] - 1;
            while (treasureDrawn < 2) {
                if (testG.deck[p][i] == copper || testG.deck[p][i] == silver || testG.deck[p][i] == gold) {
                    treasureDrawn++;
                    i--;
                }
                else {
                    otherRevealed++;
                    i--;
                }
            }
        }

        displayAll(&testG, p);
    
        printf("----------------- After playAdventurer\n");

        playAdventurer(&testG, p);

        displayDeck(&testG, p);

        // Check that deck is correct
        count = preDeck - otherRevealed - treasureDrawn;
        printf("Deck count: %d, Expected: %d\n", testG.deckCount[p], count);
        if (testG.deckCount[p] != count) {
            printf("----------------- TEST FAILED!\n");
            pass = false;
        }

        displayDiscard(&testG, p);

        // Check that discard is correct
        count = preDiscard + otherRevealed;
        printf("Discard count: %d, Expected: %d\n", testG.discardCount[p], count);
        if (testG.discardCount[p] != count) {
            printf("----------------- TEST FAILED!\n");
            pass = false;
        }

        displayHand(&testG, p);

        // Check that count of cards is correct
        count = preHand + treasureDrawn;
        printf("Hand count: %d, Expected: %d\n", testG.handCount[p], count);
        if (testG.handCount[p] != count) {
            printf("----------------- TEST FAILED!\n");
            pass = false;
        }
    }

    if (pass) {
        printf("\nAll tests passed!\n");
    }
    else {
        printf("\nSome test(s) failed!\n");
    }
    
    return 0;
}