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...
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...
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...
For this lab you are going to practice writing method signatures, implementing if statements, manipulating Strings,...
For this lab you are going to practice writing method signatures, implementing if statements, manipulating Strings, and improve your skills with for loops. The methods you will write will be part of a short trivia game, feel free to try it out after you finish.   import java.util.Scanner; public class Trivia { //TODO: isLeapYear //TODO: isPrime //TODO: aWord //TODO: reverse public static void main(String[] args){ Scanner answers = new Scanner(System.in); int score = 0; System.out.println("What year is a Leap Year?"); //...
Select five legal or ethical concepts that you feel influence nursing practice. Develop the concepts for...
Select five legal or ethical concepts that you feel influence nursing practice. Develop the concepts for both the impact on agency viability and quality patient care. Review the concepts and strategically analyze for priorities, challenges, and issues from a legal and ethical perspective Identify instances of actions taken by an agency or provider that would or could violate the ethical duties and responsibilities of the health care providers or the rights of patients Include a policy proposal, measures, and recommendations...
Engineering Standards and Codes of Practice a) With reference to the Engineers Australia Guidelines on Professional...
Engineering Standards and Codes of Practice a) With reference to the Engineers Australia Guidelines on Professional Conduct (part of their Code of Ethics), please write, in your own words, a concise summary of the requirements for competent practice See Australia Guidelines on Professional Conduct below: Engineers Australia Our Code of Ethics The Guidelines on Professional Conduct The Guidelines on Professional Conduct provide a framework for members of Engineers Australia to use when exercising their judgment in the practice of engineering....
select 2 techniques /concepts examining the relationship between the selected techniques /concepts and strategic allocation of...
select 2 techniques /concepts examining the relationship between the selected techniques /concepts and strategic allocation of financial resources with respect to revenue and expenses
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT