Question

Problem H1 (Using C++) In the main function, define four variables of type int, named: first,...

Problem H1 (Using C++)

In the main function, define four variables of type int, named: first, second, third, and total.
Write a function named getData that asks the user to input three integers and stores them in the variables first, second, and third which are in the main function.
Write a function named computeTotal that computes and returns the total of three integers.
Write a function named printAll that prints all the values in the format shown in the following sample:

1 + 2 + 3 = 6
  

Call the other three functions from the main function.

Test it once, with the values 4, 5, and 6.

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

#include<iostream>

using namespace std;  

//defination part of getData()

//it takes pointer arguments because what ever the changes made inside it ,

//that should reflect to the variables declared inside main()

void getData(int *first,int *second, int *third)

{

cout<<"Enter three values"; //asking to enter three values

cin>>*first>>*second>>*third; //input three values

}

//defination part of computeTotal()

int computeTotal(int *a, int *b, int *c)

{

return(*a+*b+*c); //return the total

}

//definationof printAll()

void printAll(int *a,int *b,int *c,int t)

{

cout<<endl<<*a<<" + "<<*b<<" + "<<*c<<" = "<<t; //print the details

}

int main()

{

int first,second,third,total; //declare four variables

getData(&first,&second,&third); //call to getData() by call by reference

total=computeTotal(&first,&second,&third); //call to computeTotal() by call by address

printAll(&first,&second,&third,total);//call tp printAll() by call by address

}

OUTPUT

CAUsersROZYnKRISHNADesktopSum.exe Enter three values1 1+2+3=6 Process exited after 2.439 seconds with return value Press any key to continue - - - CAUsers ROZYnKRISHNA Desktopisum.exe Enter three values4 5 6 4+5+6=15 Process exited after 3.567 seconds with return value Press any key to continue CAUsers ROZYnKRISHNA Desktoplsum.exe Enter three values10 15 57 10 15 5782 Process exited after 4.294 seconds with return value Press any key to continue - - -

Add a comment
Know the answer?
Add Answer to:
Problem H1 (Using C++) In the main function, define four variables of type int, named: first,...
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
  • using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average...

    using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average that Receives two integer numbers as parameter and returns the average Is used in a main function. Main() stays in a loop and asks user to enter 2 numbers and then shows the average using the Average function above Define a class named Student with following members: private data: 2 grades and a GPA (average). public constructor to initialize the members a public function...

  •     (10 pts) Define a two-dimensional array named temp with three rows and four columns of type int such that the first...

        (10 pts) Define a two-dimensional array named temp with three rows and four columns of type int such that the first row is initialized to 6, 8, 12, 9; the second row is initialized to 10, 13, 6, 16; and the third row is initialized to 27, 5, 10, 20.     (10 pts) Consider the following declarations, and see p.566: enum brands = { GM, FORD, TOYOTA, BMW, KIA }; const int N_BRANDS = 5; const int COLOR_TYPES = 6; double...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can...

    Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can i contact you? -------------------------- Program 1 - WRITE ALL THE CODE in ONE FILE...   MyArrayPtrArith1.cpp Step 1 - Define the class Write a class, myArrayClass, that creates an integer array. * Add an 'arraySize' variable, initialize to zero ( default constructor function ) * Create int * ptrArray ( default constructor set to NULL ) * Add a default constructor ( see above for...

  • Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a...

    Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a method named FillArray to interactively fill the array with any number of values up to 10 or until a sentinel value (999) is entered. If an entry is not an integer, reprompt the user. Call a second method named Statistics that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and...

  • Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values...

    Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. 2. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. This is the base code given: public class NumbersDemo { public static void main (String args[]) { // Write your...

  • #include<iostream> using namespace std; void twodigits(int original, int& first, int& second) {    first = original...

    #include<iostream> using namespace std; void twodigits(int original, int& first, int& second) {    first = original / 10;    second = original - first * 10; } int main(){ int original = 95; int first = 0; int second = 0; twodigits(original, first, second); cout << original << " => " << first << " and " << second << endl; return 0; } Write a function that takes two integers, numerator and denominator, as input parameters and output their...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • 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...

  • c++ class, coding using code blocker MinilabLoopLogic The program: You are to write a program called...

    c++ class, coding using code blocker MinilabLoopLogic The program: You are to write a program called MinilabLoopLogic which does the following Asks the user to enter 2 integers (can be one prompt or two) Gets and stores the ints Explains that the program will generate all integers that are between the numbers and are divisible by a third integer . e Asks the user for the number they should be divisible by Gets and stores that int Since 0 will...

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