Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming (20 Points): These two files need a main() to run their functions countWithList() and countWithTree(). Then all three C files need a header

  1. C programming (20 Points):

    These two files need a main() to run their functions countWithList() and countWithTree(). Then all three C files need a header file to inform them of what the others have that they need. Please finish both the main() and header.h.

    Please note! Not everything needs to be shared.

    • main() needs countWithList() and countWithTree()
    • Both countWithList() and countWithTree() need getNextNumber().
    Otherwise, it is best not to share too much, kind of like keeping methods and members private in C++ and Java.

    header.h

    /*-------------------------------------------------------------------------* *--- ---* *--- header.h ---* *--- ---* *--- ---- ---- ---- ---- ---- ---- ---- ---- ---* *--- ---* *--- Version 1a 2020 January 14 Joseph Phillips ---* *--- ---* *-------------------------------------------------------------------------*/ #include  #include  #include  #define MAX_LINE 256 #define RANGE_LOWEST 0 #define RANGE_HIGHEST 32767 #define MIN_NUM_NUMBERS 0 #define MAX_NUM_NUMBERS 0x40000000 

    main.c

    /*-------------------------------------------------------------------------* *--- ---* *--- main.c ---* *--- ---* *--- This file defines the functions getNextNumber(), ---* *--- obtainNumberBetween() and main() needed for the program of ---* *--- assignment 1. ---* *--- ---* *--- ---- ---- ---- ---- ---- ---- ---- ---- ---* *--- ---* *--- Version 1a 2020 January 14 Joseph Phillips ---* *--- ---* *-------------------------------------------------------------------------*/ #include "header.h" // PURPOSE: To hold the lowest allowed random number. int low; // PURPOSE: To hold the highest allowed random number. int high; // PURPOSE: To return another randomly-generated number. int getNextNumber () { return( (rand() % (high - low + 1)) + low ); } // PURPOSE: To repeatedly ask the user the text "Please enter ", followed // by the text in 'descriptionCPtr', followed by the numbers 'low' and // 'high', and to get an entered integer from the user. If this entered // integer is either less than 'low', or is greater than 'high', then // the user is asked for another number. After the user finally enters // a legal number, this function returns that number. int obtainNumberBetween (const char* descriptionCPtr, int low, int high ) { char line[MAX_LINE]; int entry; // YOUR CODE HERE } // PURPOSE: To use the function obtainNumberBetween() to obtain the values // for global variable 'low' (which must be between RANGE_LOWEST and // RANGE_HIGHEST), global variable 'high' (which must be between 'low' // and RANGE_HIGHEST), and local variable 'numNum' (which must be between // MIN_NUM_NUMBERS and MAX_NUM_NUMBERS). // Then it enters a loop asking the user what they want to do. If the // user chooses integer 1 then the program runs countWithList(numNums). // If the user chooses integer 2 then the program runs // countWithTree(numNums). If the user chooses 0 then the program quits. // Returns 'EXIT_SUCCESS' to OS. int main () { int numNums; int choice; low = obtainNumberBetween ("the lowest number in the range", RANGE_LOWEST, RANGE_HIGHEST ); high = obtainNumberBetween ("the highest number in the range", low, RANGE_HIGHEST ); numNums = obtainNumberBetween ("the number of numbers to consider", MIN_NUM_NUMBERS, MAX_NUM_NUMBERS ); do { const char* msgCPtr = "What would you like to do? " "(1) Count with a list " "(2) Count with a tree " "(0) Quit " "Your choice "; choice = obtainNumberBetween(msgCPtr,0,2); switch (choice) { case 0 : break; case 1 : countWithList(numNums); break; case 2 : countWithTree(numNums); break; } } while (choice != 0); return(EXIT_SUCCESS); } 

    Sample Initial Output:

    $ ./assign1-0  Please enter the lowest number in the range (0-32767): -6 Please enter the lowest number in the range (0-32767): 65536 Please enter the lowest number in the range (0-32767): 1 Please enter the highest number in the range (1-32767): 0 Please enter the highest number in the range (1-32767): 32768 Please enter the highest number in the range (1-32767): 512 Please enter the number of numbers to consider (0-1073741824): 10000000 Please enter What would you like to do? (1) Count with a list (2) Count with a tree (0) Quit Your choice (0-2): 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions