In: Computer Science
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 ...
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);
}
}