1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
raketka [301]
2 years ago
7

Write a function called calculate() that accepts three integer Numbers as arguments, compute these values : Sum and Product and

Return these computed results to the main program.
Computers and Technology
1 answer:
Dmitrij [34]2 years ago
5 0

Answer:

int* calculate(int a,int b,int c){

   int result[] = {0,0};

   int sum = a+b+c;

   int product = a*b*c;

   result[0] = sum;

   result[1] = product;

   return result;

}

Explanation:

The function is a block of the statement which performs the special task.

The function can return one integer, not more than one integer.

If we want to return multiple values then, we can use array.

we store the result in the array and return that array to the main function.

This is the only possible way to return multiple values.

So, define the function with return type array and declare the array with zero value.

Then, calculate the values and store in the variable after that, assign to the array.

Finally, return that array.  

You might be interested in
Write a program that asks for the user's first, middle, and last name as one input. The names must be stored in three different
nydimaria [60]

Answer:

Here is the C++ program:

#include <iostream>  //to use input output functions  

#include <cstring>  // used to manipulate c strings  

using namespace std;  //to identify objects cin cout

const int SIZE = 20;  //fixes constant size for firstName, middleName and lastName arrays  

const int FULL_SIZE = 60;  //constant size for fullName array  

int main() {  //start of main method  

 char firstName[SIZE]; //declares a char type array to hold first name  

 char middleName[SIZE];//declares a char type array to hold middle name  

 char lastName[SIZE]; //declares a char type array to hold last name  

 char fullName[FULL_SIZE]; //declares a char type array to hold full name

 cout << "Enter first, middle, and last name:  ";  //prompts user to enter first name

 cin>>firstName>>middleName>>lastName;  //reads last name from user, stores it in lastName array

 strcpy(fullName, lastName);  //copies last name from lastName to fullName array using strcpy method which copies a character string from source to destination

 strcat(fullName, ", "); //appends comma "," and empty space " " after last name in fullName using strcat method which appends a string at the end of another string

 strcat(fullName, firstName);  //appends first name stored in firstName to the last of fullName

 strcat(fullName, " ");  //appends an empty space to fullName

  char temp[2];  //creates a temporary array to hold first initial of middle name

temp[0] = middleName[0];  //holds the first initial of middle name

strcat(fullName, temp);  //appends first initial of middle name stored in temp to the last of fullName

strcat(fullName, ".");   //appends period

    cout<<fullName;  } //displays full name

Explanation:

I will explain the program with an example

Lets say user enters Neil as first name, Patrick as middle and Harris as last name. So firstName char array contains Neil, middleName char array contains Patrick and lastName char array contains Harris.  

Next the fullName array is declared to store Neil Patrick Harris in a specific format:

strcpy(fullName, lastName);

This copies lastName to fullName which means fullName now contains Harris.

 strcat(fullName, ", ");

This appends comma and an empty space to fullName which means fullName now contains Harris with a comma and empty space i.e. Harris,

strcat(fullName, firstName);

This appends firstName to fullName which means Neil is appended to fullName which now contains Harris, Neil

 strcat(fullName, " ");  

This appends an empty space to fullName which means fullName now contains Harris, Neil with an empty space i.e. Harris, Neil

char temp[2];

temp[0] = middleName[0];

This creates an array to hold the first initial of middle name i.e. P of Patrick

strcat(fullName, temp);

This appends an the first initial of middleName to fullName which means fullName now contains Harris, Neil P

strcat(fullName, ".");

This appends a period to fullName which means fullName now contains Harris, Neil P.

Now    cout <<"Full name is:\n"<<fullName<< endl; prints the fullName so the output of this entire program is:

Full name is:                                                                                                                                  Harris, Neil P.

The screenshot of the program along with its output is attached.

8 0
2 years ago
What is the most happy job work? that can earn $1000 per day at homes? show company website links
tamaranim1 [39]
Https://moneypantry.com/making-1000-dollars-daily/
3 0
3 years ago
Nathan notices his computer system is slowing down when he tries to copy documents to it. He also gets a prompt that warns him t
vesna_86 [32]
You would replace the hard drive
3 0
2 years ago
10. Which property is used to show the form in maximize state
user100 [1]

Answer:

windows state

Explanation:

the answer is windows state.

6 0
2 years ago
Suppose we have an arrayAofnprofessors; each teacher has two characteristics: difficulty (a numberin the range [0,10], where a h
Naily [24]

Answer:

(A)

Explanation:

4 0
2 years ago
Other questions:
  • What is the difference between chrome and chromium browser?
    9·1 answer
  • A network technician cannot get a host to connect to the internet. running the ping command shows the apipa ip address. what is
    6·1 answer
  • Which term refers to the data stored in computer memory on which the processor applies to program instructions
    11·1 answer
  • How to hack my neighboor wireless?​
    6·1 answer
  • Have you searched Buzz Ch.at on playstore​
    13·1 answer
  • Is the flow of power reversible in a leadscrew?
    11·1 answer
  • Explain the history of computing device of mechanical era
    7·1 answer
  • What is a key consideration when evaluating platforms?
    15·1 answer
  • Which statement about intellectual property is true? (CSI-7.6) Group of answer choices It is okay to use code you find on the in
    14·1 answer
  • Without this step of the problem solving process you might solve the wrong problem, not know where to start, or not know when yo
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!