Question

In: Computer Science

Write a C program with call to functions to produce the output given below. // the...

Write a C program with call to functions to produce the output given below.

// the requirements are that there should be 5 files; intList.h, intList.c, hw3.h, hw3.c, and main.c. please only C and use Linked List. thank you. For the 5 different files, he wants it this way:
1) main.c This file just consists of the main() function, which only consists of the displayClassInfo() function call, and the runMenuHw3() function call.
2) intList.h This file would have the IntNode struct definition, typedefs, and prototypes of the functions that directly manipulate your linked list, like the inserts, removes, etc.
3) intList.c This file would have the definitions of the functions that you prototyped in the intList.h file
4) hw3.h This file would have the prototypes of the functions like displayClassInfo(), runMenuHw3(), getLIWLUDigitCount(), etc. (and any other functions you want to create that don’t directly manipulate your linked list, but maybe help you in some other way to get the hw done.)
5) hw3.c This would contain the definitions of the functions that you prototyped in the hw3.h file above.

The program should display this output :

******************************************

MENU – HW #3 *   
1. getLIWLUDigitCountYourName() *
2. Quit *
******************************************

Select an option (use integer value only): -4

You are very funny here!

******************************************

MENU – HW #3 *   
1. getLIWLUDigitCountYourName() *
2. Quit *
******************************************

Select an option (use integer value only): 1

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: 1004

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: -2103451

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: 80645

Do you have an integral value (1 for yes OR 0 for no)? 0

The working list has 3 values of

1004

-2103451

80645

Calling getLIWLUDigitCountYourname() with one argument of

(1) A list of int’s
(2) The listing of values from front to end
1004
-2103451

80645

For individual values – 1004 has 3 unique digits.

-2103451 has 6 unique digits.

80645 has 5 unique digits.

After the function call was completed and a value was returned.

(1)The largest unique digit count (LUDC)is 6; and

(2) -2103451 is the largest integer with a LUDC of 6.

Releasing all elements and list!

******************************************

MENU – HW #3 *   
1. getLIWLUDigitCountYourName() *
2. Quit *
******************************************

Select an option (use integer value only): 1

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: -1

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: -22

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: 88

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: 66

Do you have an integral value (1 for yes OR 0 for no)? 0

The working list has 4 values of

-1

-22

88

66

Calling getLIWLUDigitCountYourname() with one argument of

(1) A list of int’s

(2) The listing of values from front to end

-1

-22

88

66

For individual values –

-1 has 1 unique digit(s).

-22 has 1 unique digit(s).

88 has 1 unique digit(s).

66 has 1 unique digit(s).

After the function call was completed and a value was returned.

(1) The largest unique digit count (LUDC)is 1; and

(2) 88 is the largest integer with a LUDC of 1.

Releasing all elements and list!

******************************************

MENU – HW #3 *   
1. getLIWLUDigitCountYourName() *
2. Quit *
******************************************

Select an option (use integer value only): 1

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: 1

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: -3

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: 9

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: -7

Do you have an integral value (1 for yes OR 0 for no)? 1

Enter the value: 5

Do you have an integral value (1 for yes OR 0 for no)? 0

The working list has 5 values of

1

-3

9

-7

5

Calling getLIWLUDigitCountYourname() with one argument of

(1) A list of int’s

(2) The listing of values from front to end 1

-3

9

-7

5

For individual values –

1 has 1 unique digit(s).

-3 has 1 unique digit(s).

9 has 1 unique digit(s).

-7 has 1 unique digit(s).

5 has 1 unique digit(s).

After the function call was completed and a value was returned.

(1) The largest unique digit count (LUDC)is 1; and

(2) 9 is the largest integer with a LUDC of 1.

Releasing all elements and list!

******************************************

MENU – HW #3 *   
1. getLIWLUDigitCountYourName() *
2. Quit *
******************************************

Select an option (use integer value only): 2

Having Fun ...

Solutions

Expert Solution

intList.h file :

#include <stdio.h> 
#include <stdlib.h> 

struct intNode{
    int val;
    struct intNode* next;
};

int size = 0;
struct intNode *head = NULL, *tail = NULL;
void insertList(int val);
void eraseList();
void printList();

intList.c file :

#include "intList.h"

void insertList(int val)
{
    struct intNode* newNode = malloc(sizeof(struct intNode));
    newNode->val = val;
    newNode->next = NULL;
    if(head == NULL)
    {
        head = newNode;
        tail = newNode;
    }
    else
    {
        tail->next = newNode;
        tail = newNode;
    }
    size += 1;
}

void eraseList()
{
    while(head != NULL)
    {
        struct intNode* temp = head;
        head = head->next;
        free(temp);
    }
    tail = NULL;
    size = 0;
}

void printList()
{
    struct intNode* curr = head;
    while(curr != NULL)
    {
        printf("%d\n",curr->val);
        curr = curr -> next;
    }
}

hw3.h file :

#include "intList.c"

int displayClassInfo();
void runMenuHw3(int choice);
void getLIWLUDigitCountYourname();

hw3.c file :

#include "hw3.h"

int displayClassInfo()
{
    printf("*************************************\n");
    printf("MENU - HW #3 *\n");
    printf("1. getLIWLUDigitCountYourName() \n");
    printf("2. Quit *\n");
    printf("*************************************\n");
    printf("Select an option (use integer value only): ");
    int opt;
    scanf("%d",&opt);
    return opt;
}

void getLIWLUDigitCountYourname()
{
    struct intNode* curr = head;
    printf("For individual values - \n");
    int uniq = 0, ans = 0;
    while(curr != NULL)
    {
        int num = curr->val;
        if(num < 0)
            num *= -1;
        int dig[10] = {0};
        while(num != 0)
        {
            int rem = num % 10;
            num /= 10;
            dig[rem] = 1;
        }
        int cnt = 0;
        for(int i = 0; i < 10; i++)
        {
            if(dig[i] == 1)
                cnt += 1;
        }
        printf("%d has %d unique digit(s)\n",curr->val,cnt);
        if(cnt > uniq)
        {
            uniq = cnt;
            ans = curr->val;
        }
        else if(cnt == uniq)
        {
            if(curr->val > ans)
                ans = curr->val;
        }
        curr = curr->next;
    }
    printf("After the function call was completed and a value was returned.\n");
    printf("(1) The largest unique digit count (LUDC)is %d; and\n(2) %d is the largest integer with a LUDC of %d.\n",uniq,ans,uniq);
    printf("Releasing all elements and list!\n");
    eraseList();

}

void runMenuHw3(int opt)
{
    if(opt == 1)
    {
        int flag = -1;
        while(flag != 0)
        {
            printf("Do you have an integral value (1 for yes OR 0 for no)? ");
            scanf("%d",&flag);
            if(flag == 1)
            {
                int val;
                printf("Enter the value: ");
                scanf("%d",&val);
                insertList(val);
            }
            else if(flag == 0)
            {
                printf("The working list has %d values of \n",size);
                printList();
                printf("Calling getLIWLUDigitCountYourname() with one argument of \n(1) A list of int's \n(2) The listing of values from front to end\n");
                printList();
                getLIWLUDigitCountYourname();
            }
        }
    }
    else if(opt == 2)
    {
        printf("Having Fun ...\n");
    }
    else{
        printf("You are very funny here!\n");
    }
}

main.c file : Since it is not clearly mentioned what displayClassInfo() function does, so I have used it as displaying the initail menu for the user.

#include "hw3.c"

int main()
{
    int opt = -1;
    while(opt != 2)
    {
        opt = displayClassInfo();
        runMenuHw3(opt);
    }
}

Related Solutions

PROBLEM: Write a C program that will produce the EXACT output shown below. Using initialization lists,...
PROBLEM: Write a C program that will produce the EXACT output shown below. Using initialization lists, create 5 one-dimensional arrays, one for each of these: hold the names of the people running in the election (see note below) hold the names of the subdivision (see note below) hold the vote counts in the Aberdeen subdivision for each candidate hold the vote counts in the Brock subdivision for each candidate hold the vote counts in the Sahali subdivision for each candidate...
Edit the given program to produce the following output in c++ mode: - Take in the...
Edit the given program to produce the following output in c++ mode: - Take in the name of a superhero & tell him how many villains he/she has to defeat today - The number of villains is randomly generated and should be a number between 11 and 42. - Use a seed of 7. Hint: Compile the program first before making edits What is your name? Hello Captain America There are 42 villains you need to defeat today Oops! one...
Write C++ program as described below. Call this programChill.cpp. In April 2018 the lowest and the...
Write C++ program as described below. Call this programChill.cpp. In April 2018 the lowest and the highest temperatures ever recorded in Ohio are 25F and 81F, respectively. The wind chill factor is the perceived temperature when taking temperature and wind into account. The standard formula for wind chill factor (from the US Weather Service) is: 0.0817 * (3.71 * sqrt(Wind) + 5.81 – 0.25 * sqrt(Wind)) * (Temp – 91.4) + 91.4 where ‘sqrt’ is the square root, Wind is...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt...
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt the user to enter the sales amount and computes and prints with a description the commission paid to salesperson as follows: 10% for sales amount less than $2,000.00, 15% for sales amount less than $10,000.00 and 20% for sales amount less than $20,000.00, then function calc_commission calls another function name assign_base_salary() to ask the user to enter each of 5 salesperson’s base salary ,...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
In C++ Prototype your functions above "main" and define them below "main"; Write a program that...
In C++ Prototype your functions above "main" and define them below "main"; Write a program that uses two identical arrays of at least 20 integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in ascending order. The function should keep count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other arrays. It should also keep count...
write C++ program using functions (separate function for each bottom) Write a program to find if...
write C++ program using functions (separate function for each bottom) Write a program to find if a number is large word for two given bottom base - bottom1 and bottom2. You can predict that a number, when converted to any given base shall not exceed 10 digits. . the program should ask from user to enter a number that it should ask to enter the base ranging from 2 to 16 after that it should check if the number is...
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
write a program on c++ that outputs a calendar for a given month in a given...
write a program on c++ that outputs a calendar for a given month in a given year, given the day of the week on which the 1st of the month was. The information in numeric format (months are: 1=Januay, 2=February 3=March, 4= April, 5= May, 6= June, 7= July... etc days are 1=Sunday, 2=Monday, 3= Tuesday, 4= Wednesday, 5= Thursday, 6= Friday and 7= Saturday ). The program output that month’s calendar, followed by a sentence indicating on which day...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT