Question

Please follow the instructions below to create a code. The instructions are broken down into a...

Please follow the instructions below to create a code. The instructions are broken down into a few steps.

Create the following functions along with a driver for each one confirming it works. The driver needs to test the function with at least 5 different inputs, although more is always better.

Be sure to use the function display_startup_banner( ) in all of your drivers.

Please create separate files for each code. That is, if you're creating a function called learning_online_is_a_trip( ) put it in a file called learning_online_is_a_trip.c and then compile it along with your driver.

Part 1 Using the function prototype

void print_all_integers( const int array[ ], const int elements, const char header[], const char tag[ ] );

create a function that displays the following

Displaying array sample1

sample1: [ 0 ] = 68

sample1: [ 1 ] = 94

sample1: [ 2 ] = 71

sample1: [ 3 ] = 60

4 elements displayed.

The string "Displaying array sample1" is passed in as header.

The sting "sample1" is passed in as tag.

Part 2 Write a function that takes an array of n integers and prompts the user to enter values for each of the elements.

Allow the user to end the program by entering a sentinel value passed in to the function when it is invoked.

Part 3 Write a function that takes an array of n integers and fills it with random numbers from x to y. For example, if I have an array of 4 integers and I want it filled with random numbers from 60 to 100, I might end up with the array shown.

Use the rand( ) function to generate the appropriate random numbers, and the srand( time( NULL ) ) function call to seed the random number generator.

Part 4 Using the following programmer-defined type definitions:

typedef enum { clubs, diamonds, hearts, spades } suit_t;

typedef enum { ace = 1, two, three, four, five, six, seven, eight, nine, ten, jack, queen, king } rank_t;

Write a function that accepts an array of five pairs of suit_t and rank_t values.

The function should return true if there are three matching suit_t values, or it should return true if there are three matching rank_t values, otherwise it should return false.

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

B)

#include <stdio.h>

#include <stdlib.h>

void print_all_integers( const int array[], const int elements, const char header[], const char tag[] ){

    printf(header);

    printf("\n");

    for(int i=0;i<elements;i++){

        printf("%s: [ %d ] = %d\n",tag,i,array[i]);

    }

    printf("%d elements displayed.",elements);

}

void input(int array[], int *n){

    printf("Input Array values. (-1) to stop...\n");

    int x=1;;

    while(x!=-1){

        

        printf("array: [ %d ] = ",*n);

        scanf("%d",&x);

        if(x==-1)

            return;

        array[(*n)++]=x;

    }

}

int main(int argc, char const *argv[])

{

    int array[100];

    int elements=0;

    input(array,&elements);

    char tag[] = "array";

    char header[] = "Displaying array";

    print_all_integers(array,elements,header,tag);

    return 0;

}

----------------------------------------------------------------------------------------------------

A)

Displaying array samplel samplel: [ 0 ] = 68 samplel: [ 1 ] = 94 sample1: [ 2 ] = 71 sample1: [ 3 ] = 60 4 elements displayed

#include <stdio.h>

#include <stdlib.h>

void print_all_integers( const int array[], const int elements, const char header[], const char tag[] ){

    printf(header);

    printf("\n");

    for(int i=0;i<elements;i++){

        printf("%s: [ %d ] = %d\n",tag,i,array[i]);

    }

    printf("%d elements displayed.",elements);

}

int main(int argc, char const *argv[])

{

    int array[] = {68,94,71,60};

    int elements = 4;

    char tag[] = "sample1";

    char header[] = "Displaying array sample1";

    print_all_integers(array,elements,header,tag);

    return 0;

}

--------------------------------------------------------

C)

#include <stdio.h>

#include <stdlib.h>

void print_all_integers( const int array[], const int elements, const char header[], const char tag[] ){

    printf(header);

    printf("\n");

    for(int i=0;i<elements;i++){

        printf("%s: [ %d ] = %d\n",tag,i,array[i]);

    }

    printf("%d elements displayed.",elements);

}

void fill(int array[], int n,int x,int y){

    printf("generating Random values...\n");

    srand(time(NULL));

    for(int i=0;i<n;i++)

        array[i] = rand()%(y-x)+(x);

}

int main(int argc, char const *argv[])

{

    int array[5];

    int elements=5;

    fill(array,elements,60,100);

    char tag[] = "array";

    char header[] = "Displaying array";

    print_all_integers(array,elements,header,tag);

    return 0;

}

Add a comment
Know the answer?
Add Answer to:
Please follow the instructions below to create a code. The instructions are broken down into a...
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
  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • Hi!, having trouble with this one, In this class we use visual studio, C++ language --------------------------------------------------------------...

    Hi!, having trouble with this one, In this class we use visual studio, C++ language -------------------------------------------------------------- Exercise #10 Pointers - Complete the missing 5 portions of part1 (2 additions) and part2 (3 additions) Part 1 - Using Pointers int largeArray (const int [], int); int largePointer(const int * , int); void fillArray (int * , int howMany); void printArray (const char *,ostream &, const int *, int howMany); const int low = 50; const int high = 90; void main()...

  • Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the...

    Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the size of an array. Then create an integer array of that exact size. Ask the user to enter a maximum value and then write a loop to fill the array with random numbers with value in the range of 1 to the maximum value. For example, if the maximum value is 100, random numbers must have value 1 to 100 inclusive. Input size of...

  • IN C++ Create a class to act as a generic array (i.e. the user will be...

    IN C++ Create a class to act as a generic array (i.e. the user will be able to choose the data type to be stored by passing the appropriate template argument. Integer template arguments will also be used to set the upper and lower bounds of the array. Provide all necessary functionality to allow the class to act as an array ([] operator, = operator etc.). The array does not need to provide input or output methods to act on...

  • In C++ please! *Do not use any other library functions(like strlen) than the one posted(<cstddef>) in the code below!* /** CS 150 C-Strings Follow the instructions on your handout to complete t...

    In C++ please! *Do not use any other library functions(like strlen) than the one posted(<cstddef>) in the code below!* /** CS 150 C-Strings Follow the instructions on your handout to complete the requested function. You may not use ANY library functions or include any headers, except for <cstddef> for size_t. */ #include <cstddef> // size_t for sizes and indexes ///////////////// WRITE YOUR FUNCTION BELOW THIS LINE /////////////////////// ///////////////// WRITE YOUR FUNCTION ABOVE THIS LINE /////////////////////// // These are OK after...

  • 17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int...

    17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int array1[20] = {3, 18, 1, 25, 4, 7, 30, 9, 80, 16, 17}; int numElements = 11; cout << "Part 1" << endl; // Part 1 // Enter the statement to print the numbers in index 4 and index 9 // put a space in between the two numbers    cout << endl; // Enter the statement to print the numbers 3 and 80...

  • Please follow the instructions carefully. Thank you! For the second activity, I outputted the superhero class...

    Please follow the instructions carefully. Thank you! For the second activity, I outputted the superhero class below. SUPERHERO CLASS public class Superhero{   private String alias;   private String superpower;   private int health;   public Superhero(){       alias= "unkown";       superpower= "unknown";       health= 50; //Realized I did not use default constructor while going through instructions of lab   }   public Superhero(String alias1, String superpower1,int health1 ){       alias=alias1;       superpower=superpower1;       if(health1>=0 && health1<=50)           health= health1;       else if(health1<0||health1>50)           health=25;   }   public void setalias(String alias1){       alias=alias1;   }   public void setsuperpower(String...

  • c++ help please! Create a 2D character array in your main function and use nested for...

    c++ help please! Create a 2D character array in your main function and use nested for loops to fill the array with the letter ‘e’ to represent empty spaces. Create a function to print the board on the screen using a nested for loop. The function header is: void printBoard (char board [][3]) Create a function that checks whether a particular space has already been filled. If the space is filled it returns a boolean value of true, otherwise false....

  • Two-dimensional arrays and functions Write the code CIS22A-HW7-XXXXX.cpp to create and print a 12 x 12...

    Two-dimensional arrays and functions Write the code CIS22A-HW7-XXXXX.cpp to create and print a 12 x 12 multiplication table using a 2-dimensional array and functions with nested loops. Define the following Global Constants at the top, before main function: const int ROW_SIZE = 12; const int COL_SIZE = 12; const int WIDTH = 4; Two required functions are: void createTable(int [][COL_SIZE], int rows); void printTable(int [][COL_SIZE], int rows); Use this main code without any change: int main() {         int table[ROW_SIZE]...

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
ADVERTISEMENT