void displayAllWords(char** articles, char ** nouns, char ** verbs, char ** preps, int aSize, int  nSize, int  vSize, int  pSize)
{
    printf("\nArticles: ");
    printArray2D(articles, aSize);
    printf("\nNouns: ");
    printArray2D(nouns, nSize);
    printf("\nVerbs: ");
    printArray2D(verbs, vSize);
    printf("\nPrepositions: ");
    printArray2D(preps, pSize);
}
Exemple #2
0
int main(void)
    {
    int size = 25;
    int* a = malloc(sizeof(int) * size);
    int* temp = malloc(sizeof(int) * size);

    printf("----> 1D Array Sorting <----\n\n");
    printf("insertionSort\n");
    createRandomArray(a, size);
    printArray(a, size);
    insertionSort(a, size);
    printArray(a, size);
    printf("\n");

    printf("selectionSort\n");
    createRandomArray(a, size);
    printArray(a, size);
    selectionSort(a, size);
    printArray(a, size);
    printf("\n");

    printf("mergeSort\n");
    createRandomArray(a, size);
    printArray(a, size);
    mergeSort(a, size, temp);
    printArray(a, size);
    printf("\n");

    printf("quickSort\n");
    createRandomArray(a, size);
    printArray(a, size);
    quickSort(a, 0, size-1);
    printArray(a, size);
    printf("\n");

    printf("----> 2D Array Sorting <----\n\n");
    int rows = 5, cols = 5;
    int** a2D = malloc(sizeof(int*) * rows);
    int i;
    for(i = 0; i < rows; i++)
        {
        a2D[i] = malloc(sizeof(int) * cols);
        }

    printf("insertionSort\n");
    createRandom2DArray(a2D, cols, size);
    printArray2D(a2D, rows, cols);
    insertionSort2D(a2D, cols, size);
    printArray2D(a2D, rows, cols);
    printf("\n");

    return EXIT_SUCCESS;
    }
int _tmain(int argc, _TCHAR* argv[])
{

	const int width = 10;
	const int height = 5;
	float arr[width * height];
	srand(7);
	for (size_t i = 0; i < height; i++)
	{
		for (size_t j = 0; j < width; j++)
		{
			
			float f =  (rand() * 1.0f /  (RAND_MAX));
			arr[IDX(j, i, width)] = f;
		}
	}

	printArray2D(arr, width, height);
	std::cout << std::endl << "smooth arr:" << std::endl;
	
	smoothArray2D(arr, width, height);
	

	system("pause");
	return 0;
};
void displayTogetherSorted(char** articles, char ** nouns, char ** verbs, char ** preps, int aSize, int  nSize, int  vSize, int  pSize)
{
    char ** allWords;
    int total = 0;
    int currentTot = 0, i = 0;
    total = (aSize+nSize+vSize+pSize);

    allWords = (char**) malloc(total * sizeof(char *));

    for(i = 0; i < aSize; i++)
        {
            allWords[currentTot] = (char*) malloc(strlen(articles[i]) * sizeof(char*));
            strcpy(allWords[currentTot], articles[i]);
            currentTot++;
        }
    for(i = 0; i < nSize; i++)
        {
            allWords[currentTot] = (char*) malloc(strlen(nouns[i]) * sizeof(char*));
            strcpy(allWords[currentTot], nouns[i]);
            currentTot++;
        }
    for(i = 0; i < vSize; i++)
        {
            allWords[currentTot] = (char*) malloc(strlen(verbs[i]) * sizeof(char*));
            strcpy(allWords[currentTot], verbs[i]);
            currentTot++;
        }
    for(i = 0; i < pSize; i++)
        {
            allWords[currentTot] = (char*) malloc(strlen(preps[i]) * sizeof(char*));
            strcpy(allWords[currentTot], preps[i]);
            currentTot++;
        }
    sortStringArray(allWords,total);
    printArray2D(allWords,total);
}
int main()
{
    FILE * fin = NULL;
    char fn[MAX], input[MAX], word[MAX];
    int choice = 0;
    int sentSize = 5;
    int aSize, nSize, vSize, pSize;
    char ** articles = NULL;
    char ** nouns = NULL;
    char ** verbs = NULL;
    char ** preps = NULL;
    char ** sentence = NULL;

    srand(time(NULL));

    readFileName(fn);
    openFile(fn, fin, &aSize, &nSize, &vSize, &pSize);
    articles = fillArray(fn,"article", articles, aSize, fin);
    nouns = fillArray(fn,"noun", nouns, aSize, fin);
    verbs = fillArray(fn,"verb", verbs, aSize, fin);
    preps = fillArray(fn,"preposition", preps, aSize, fin);
    displayAmounts(aSize, nSize, vSize, pSize);

    sortStringArray(articles, aSize);
    sortStringArray(nouns, nSize);
    sortStringArray(verbs, vSize);
    sortStringArray(preps, pSize);

     do
	{
		choice = menu();

		if(choice == 1)
		{
			sentence = createSentence(articles, nouns, verbs, preps, aSize, nSize, vSize, pSize);
			printArray2D(sentence,sentSize);

		}// end choice == 1

		else if(choice == 2)
		{
			displayAllWords(articles, nouns, verbs, preps, aSize, nSize, vSize, pSize);
		}// end choice == 2

		else if(choice == 3)
		{
            whichArray(input);
		    whatWord(word);
		    if(strcmp(input,"ARTICLES") == 0)
                addWord(articles, word, &aSize);
            else if(strcmp(input,"NOUNS") == 0)
                addWord(nouns, word, &nSize);
            else if(strcmp(input,"VERBS") == 0)
                addWord(verbs, word, &vSize);
            else if(strcmp(input,"PREPOSITIONS") == 0)
                addWord(preps, word, &pSize);
		}// end choice == 3

		else if(choice == 4)
		{
			whichArray(input);
			whatWord(word);
            if(strcmp(input,"ARTICLES") == 0)
                removeWord(articles, word, &aSize);
            else if(strcmp(input,"NOUNS") == 0)
                removeWord(nouns, word, &nSize);
            else if(strcmp(input,"VERBS") == 0)
                removeWord(verbs, word, &vSize);
            else if(strcmp(input,"PREPOSITIONS") == 0)
                removeWord(preps, word, &pSize);

		}// end choice == 4

		else if(choice == 5)
		{
            displayTogetherSorted(articles, nouns, verbs, preps, aSize, nSize, vSize, pSize);
		}// end choice == 5

	}while(choice != 6);

    return 0;
}