Question

In: Computer Science

Concepts to Practice • Pointers • Simulated “pass by reference” via pointers • Strings • Relationship...

Concepts to Practice • Pointers • Simulated “pass by reference” via pointers • Strings • Relationship of pointers to arrays

Description For the prelab assignment, you need to implement a program that issues prompts and takes in data from the user inside various functions. There are special rules in this assignment to make sure you pass variables back and forth between your functions and the main() function: • You may not call scanf() from your main() function. • You may not use global variables. • The variables you print out at the end must all be declared in your main() function. • All of your functions must have a void return type, except as described below. The main() function in your program should: 1. Print a message welcoming the user to Prelab 8. 2. Call a function to get an integer and a floating point variable from the user. 3. Call a function to get a string from the user. 4. Call a function to get an integer array from the user. 5. Print out all of the values that the user entered. Functions You Must Write You may write any functions you wish to implement this program, but there must be a function to get an integer and a float, a function to get a string, and a function to get an array. To get the array, you must write a function with the following prototype: int GetIntegerArray(int * outputIntArray, int maxsize); The GetIntegerArray() function should return the actual number of array elements entered. Its parameters are the location in memory where it should begin filling in the array elements (outputIntArray), and the maximum number of elements (maxsize) that you can enter (so you won’t run off the end of the array). Sample Output jimr@JimRArea51:~/CS1050/FS2020/labs/lab8$ compile prelab8.c jimr@JimRArea51:~/CS1050/FS2020/labs/lab8$ ./a.out *********************** * Welcome to Prelab 8 * *********************** Please enter an integer followed by a space followed by a float and then hit enter: 123 27.391 Please enter a string without spaces and then hit enter: MizzouBeatTheDefendingNationalChampions! How many integers would you like to input? 4 Enter integer #1: 18 Enter integer #2: 23 Enter integer #3: 475 Enter integer #4: 32768 *********************** You entered 123,27.39,MizzouBeatTheDefendingNationalChampions! Array elements: array[0]=18 array[1]=23 array[2]=475 array[3]=32768

Solutions

Expert Solution

Please find the requested program below. Also including the screenshot of sample output and screenshot of code to understand the indentation.

Please provide your feedback
Thanks and Happy learning!

#include <stdio.h>

void getIntAndFloatFromUser(int &intInput, float &floatInput)
{

    printf("Please enter an integer followed by a space followed by a float and then hit enter : ");
    scanf("%d%f", &intInput, &floatInput);
}

void getStringFromUser(char* stringInputArray)
{

    printf("Please enter a string without spaces and then hit enter : ");
    scanf("%s", stringInputArray);
}

int GetIntegerArray(int * outputIntArray, int maxsize)
{
    int inputCount = 0;

    while (inputCount < 1 || inputCount > 100)
    {
        printf("How many integers would you like to input ? ");
        scanf("%d", &inputCount);
        if (inputCount < 1 || inputCount > 100)
        {
            printf("Input count is bigger than the maximun size(100) allowed.\n");
        }
    }

    for (int i = 0; i < inputCount; i++)
    {
        printf("Enter integer #%d: ", i+1);
        scanf("%d", &outputIntArray[i]);
    }

    return inputCount;
}

int main()
{
    int intInput = 0;
    int totalElementsInIntArray = 0;
    float floatInput = 0;
    char stringInputArray[100] = { '\0' };
    int  outputIntArray[100];

    printf("*********************** * Welcome to Prelab 8 * ***********************\n");
    getIntAndFloatFromUser(intInput, floatInput);
    getStringFromUser(stringInputArray);
    totalElementsInIntArray = GetIntegerArray(outputIntArray, 100);

    printf("*********************** You entered ***********************\n");
    printf("%d, %.2f, %s\n", intInput, floatInput, stringInputArray); 
    printf("Array elements : ");
    for (int i = 0; i < totalElementsInIntArray; i++)
    {
        printf("array[%d] = %d ", i, outputIntArray[i]);
    }

    return 0;
}

Related Solutions

Give one example that will show that pass by value, pass by Reference, pass by name,...
Give one example that will show that pass by value, pass by Reference, pass by name, pass by value result are all different.
Objectives: Practice using files and strings. More practice using loops with files and strings Background Assume...
Objectives: Practice using files and strings. More practice using loops with files and strings Background Assume you're working on a contract where the company is building a e-mailing list. Your task is to write a C++ program that reads through an e-mail stored in the current working directory, called mail.dat, and outputs every email address found as individual lines to a file called email_list.dat. For this assignment, if a whitespace delimited string of characters has an embedded commercial at sign...
What is pass-by-reference? What is pass-by-value? What is a memory leak? What happens if the function...
What is pass-by-reference? What is pass-by-value? What is a memory leak? What happens if the function makes a change to that received array and why? Functions in C++ can return only one data item (e.g., variable) using the return statement and they also cannot return arrays. There is, however, another way to "return" more than one item from a function without using the return statement. Can you explain how and why? How are arrays represented in memory? What is the...
Integer Pointers Program and Analysis Demonstrate an understanding of basic C++ programming concepts by completing the...
Integer Pointers Program and Analysis Demonstrate an understanding of basic C++ programming concepts by completing the following: Program: Create a C++ program that asks the user to enter three integer values as input. Store the values into three different variables. For each variable, create three integer pointers that point to each value. Display the contents of the variables and pointers. In your program, be sure to use the new operator and delete operators to management memory. Program Analysis: Given your...
synthesize and integrate nursing practice concepts into their professional nursing practice. engage in professional nursing practice...
synthesize and integrate nursing practice concepts into their professional nursing practice. engage in professional nursing practice that is patient-centered and appropriate for diverse individuals, families, and communities. Provide patient-centered care that is respectful to diverse beliefs, and attitudes. 1. Exemplar of specific behavior that met competency.
C# in Visual Studio Practice Concepts ● Practice using conditional logic and expressions ● Practice protecting...
C# in Visual Studio Practice Concepts ● Practice using conditional logic and expressions ● Practice protecting numeric input prompts (Int.TryParse(Console.ReadLine(), out); Problem Description create a Console Application using the .NET Framework. C# This project will implement a short 3-question quiz. Create a quiz application that has 3 questions. At least one of the questions must offer multiple choices, and at least one question must prompt the user to enter a numeric input. The third question can be either multiple choice...
Quick Revision of basic ideas about strings – 695-701. Do this via strategic questions of the...
Quick Revision of basic ideas about strings – 695-701. Do this via strategic questions of the students Use set 5.1 StringSorts slides 1-16. Again if the lecturer has a computer in the lectern, it would be helpful to go through some of the code snippets throughout this lecture. Go through 51DemoKeyIndexed Counting slides 1-19 – preferably by having the students act it out as before in conjunction with slides 17-21 of 5.1 StringSorts. Try to cover at least LSD and...
Question 3: C-Strings and pointers (10 pts) [5] The following function appends C-string str2, to C-string...
Question 3: C-Strings and pointers (10 pts) [5] The following function appends C-string str2, to C-string str1. Complete the function using array access, i.e. str1[i], but no pointer access. Note: For both part a) and part b) you may not use any library function calls (e.g. you cannot use strlen, strcat, etc.) // Append strt2 to str1 void my_strcat(char str1[], char str2[]) { //YOUR CODE HERE   } // example of using my_strcat() #include <stdio.h> int main(void) { char my_str1[50] =...
BRIEFLY DEFINE OR EXPLAIN THE FOLLOWING COMBINATIONS OF CONCEPTS AND THE RELATIONSHIP BETWEEN THE CONCEPTS: a....
BRIEFLY DEFINE OR EXPLAIN THE FOLLOWING COMBINATIONS OF CONCEPTS AND THE RELATIONSHIP BETWEEN THE CONCEPTS: a. marginal benefit, marginal cost, optimal allocation of resources b. scarcity, opportunity cost, and rationing device (explain the role of a rationing device and discuss two different types of rationing devices or allocative mechanisms) c. decreasing opportunity costs, increasing opportunity costs, constant opportunity costs       d. economic efficiency, technical efficiency, allocative efficiency e. consumer surplus, producer surplus f. demand price, supply price, market price, equilibrium price
This C++ program will use arrays, recursion, and pass by reference to calculate 02, 12, 22,...
This C++ program will use arrays, recursion, and pass by reference to calculate 02, 12, 22, 32, 42 and then print a message. Write a driver program (main) that includes the following: An array class (not a built-in-array) of 5 integers initialized to 0,1,2,3,4 the bases An integer initialized to 2 to hold the exponent A string initialized to “Good Job!\n”; A for loop that calls the recursive pow function with all of the bases and the exponent. Call the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT