Question

Write a function called FirstElements for adding 100 random integers between 100 to 1000 to myList. using C program

Project: List management Goa l: creating, updating and displaying a list using a menu. Instruction: Create an array called myList. Write a function called FirstElements for adding 100 random integers between 100 to 1000 to myList Initialize the first 100 elements of myList by calling the FirstElements function. Create a menu to display the following options and a number corresponding to each option which is used for selecting the desired option: Create a menu to dihefolwing ootions and a number 1- adding any amount of numbers to myList o 2-removing all occurrences of a selected number from myList o 3- finding and displaying the maximum, minimum and range (maximum-minimum) in myList o 4- finding the number of occurrences of a number in myList o5- doubling (multiplying by 2) all numbers in myList o 6- display all members of myList. o 7- quit for each menu item create a function. when the item number is typed, the function should be executed, the required inputs should be requested, and the proper output should be produced. the outputs can be formatted in a proper fashion of your choice after executing any function in the menu, the user should be given the choice to select another menu or quit (Y for the new request and Q for quit). · if the user has a new request, the menu should appear again and the process repeated.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<stdlib.h>
void FirstElements(int *array)
{
   int i=0;
   for(i=0;i<100;i++)
   array[i]=100+rand()%(1000-100);  
}

int Add(int *myList,int i)
{
   int x=0;
       printf("\nEnter the number to be added : ");
           scanf("%d",&x);
           myList[i++]=x;
           printf("\n");
           return i;
}


int Delete(int *myList,int i)
{
   int s=0,k=0,flag=0;
       printf("\nEnter the number to be deleted : ");
           scanf("%d",&s);
           for(k=0;k<i;k++)
           {
               if(myList[k]==s){
               myList[k]=0;
               flag=1;
               }
              
           }
          
           if(flag==0)printf("\nNumber not found");
           printf("\n");
           printf("\n");
           return i;
}

int MaxMin(int *myList,int i)
{
   int min=0,max=0,k=0;
   min=myList[0];
   max=myList[0];
  
   for(k=0;k<i;k++)
           {
               if(myList[k]>max) max=myList[k];
               if(myList[k]<min) min=myList[k];
           }
           printf("\nMaximum=%d, Minimum=%d, Range=%d",max,min,max-min);
           printf("\n");
           return i;
}


int Search(int *myList,int i)
{
   int k=0,s=0,flag=0;
       printf("\nEnter the number to be searched : ");
           scanf("%d",&s);
           for(k=0;k<i;k++)
           {
               if(myList[k]==s){
               printf("\nNumber found at %d place in myList",k+1);
               flag=1;  
               }
              
           }
           if(flag==0)printf("\nNumber not found");
           printf("\n\n");
   return i;
}


int Double(int *myList,int i)
{
   int k=0;
           for(k=0;k<i;k++)
           {
               myList[k]=2*myList[k];
           }
              
   return i;      
}

int Print(int *myList,int i)
{
   int k=0;
       printf("\nmyList is :\n");
               for(k=0;k<i;k++)
           {
               printf("\nmyList[%d]=%d",k+1,myList[k]);
           }
           printf("\n");
           return i;
}
int main()
{
   int i=0,p=0;
   int myList[10000]={0};
   FirstElements(myList);  
   i=100;
   char ch[2]={'Y','\0'};
   while(p!=7)
   {
      
       printf("Press 1 to add number to myList");
       printf("\nPress 2 to remove all occurences of a seleted number from myList");
       printf("\nPress 3 to display maximum, minimum and range in myList");
       printf("\nPress 4 to find the number of occurences of a number in myList");
       printf("\nPress 5 to doubling all the numbers in myList");
       printf("\nPress 6 to display all the members of myList");
       printf("\nPress 7 to Quit");
       printf("\nEnter your choice : ");
       scanf("%d",&p);
       if(p==1)
       {
           i=Add(myList,i);      
       }
       else if(p==2)
       {
           i=Delete(myList,i);  
       }
       else if(p==3)
       {
           i=MaxMin(myList,i);
       }
       else if(p==4)
       {
           i=Search(myList,i);
       }
      
       else if(p==5)
       {
           i=Double(myList,i);
       }
       else if(p==6)
       {
           i=Print(myList,i);
       }
       else if(p==7)
       {
           exit(1);
       }
       else if(p>=8 && p<1)
       {
           printf("\nWrong Choice of p Entered");
       }
      
       printf("\nPress Y for new request or Q to exit :");
       scanf("%s",&ch);
       while(ch[0]!='Y'){
      
       if(ch[0]=='Q')
       exit(1);
       else if (ch[0]=='Y')break;
      
       printf("\nPress Y for new request or Q to exit :");
       scanf("%s",&ch);
       }
   }
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a function called FirstElements for adding 100 random integers between 100 to 1000 to myList....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 -...

    Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1: Create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: Create a Function that will sum and output all the odd numbers in the array. Function 3: Create a Function that will sum and output all the...

  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

  • Write a Java Program that performs the following functionalities: and you can use if statements, cases,...

    Write a Java Program that performs the following functionalities: and you can use if statements, cases, and string methods Enter a new main sentence Find a String Find all incidents of a String Find and Replace a String Replace all the incidents of a String Count the number of words Count a letter’s occurrences Count the total number of letters Delete all the occurrences of a word Exit The program will display a menu with each option above, and then...

  • Objectives: Integer arithmetic, Functions, menus. Write a C++ program that displays the following menu of choices....

    Objectives: Integer arithmetic, Functions, menus. Write a C++ program that displays the following menu of choices. 1. Find the number of digits in an integer. 2. Find the nth digit in an integer. 3. Find the sum of all digits of an integer. 4. Is the integer a palindrome? 5. Quit Enter a choice: Page 1 of 4 For each of the choices (1, 3, 4), Read a positive integer number and call a function that processes the menu choice...

  • Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel –...

    Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel – sentinel is used to indicate the end of input and must not to be considered as the valid data for the computation). Perform the following operations for the integers entered by the user. Display the sum of the numbers less than 100 Display the smallest of the positive integers Display the largest of the negative integers Display how many integers are between 100 and...

  • 2. Write a C++ program, that generates a set of random integers and places them in...

    2. Write a C++ program, that generates a set of random integers and places them in an array. The number of values generated and their range are entered by the user. The program then continually prompts the user for one of the following character commands: a: display all the values I: display the values less than a given value g display the values greater than a given value e: display all odd values o: display all even values q: quit...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • The language is C++ for visual studio express 2013 for windows create a TicketManager class and...

    The language is C++ for visual studio express 2013 for windows create a TicketManager class and a program that uses the class to sell tickets for a performance at a theater. Here are all the specs. This is an intense program, please follow all instructions carefully. -I am only creating the client program that uses the class and all it's functions -The client program is a menu-driven program that provides the user with box office options for a theater and...

  • Derive a class called Stack from the linked list described in Assignment 2 (list of Dates)....

    Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions become private in the...

  • Note: You must write this program in Python. General Requirements The program should display a menu...

    Note: You must write this program in Python. General Requirements The program should display a menu and allow the user to perform one of the following tasks. Add an item to the list Delete an item from the list Print the list Print the list in reverse Quit the program The program should run until the user chooses to quit. In Python, programmatically quitting the application is achieved with the exit() procedure. You should use a List to store the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT