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
IgorLugansk [536]
3 years ago
11

Write a C++ program which prompts user to choose from the two alternative funtions specified below, each of which passes a rando

m number between 1 and 4 and returns a random message. The two functions are: a) Function messageByValue that passes a random value between 1 and 4 and returns the message by value and b) Function messageByReference that passes a random value between 1 and 4 and returns the message by reference.
Computers and Technology
1 answer:
melomori [17]3 years ago
3 0

Answer:

#include <iostream>   //header file

#include <stdlib.h>    

#include <time.h>      

using namespace std;       // using namespace

string call_by_value(int num)    // call by value

{

  if(num==1)

  return "hello sir!";

  if(num==2)

  return "what's going on?";

  if(num==3)

  return "howz you master?!";

  if(num==4)

  return "i m fine!";

}

string call_by_reference(int *num)       //call by reference

{

  if(*num==1)

  return "hello sir!!";

  if(*num==2)

  return "what's going on?";

  if(*num==3)

  return "howz you master?";

  if(*num==4)

  return "i m fine";

}

int main() {                      //main function

  int n,v,r;

  string str;

  srand (time(NULL));

  cout<<"enter a value 1 and 2 for choice and -1 for exit : ";

  cin>>n;

  while(n!=-1)

  {

      if(n==1)

      {

          int num = (rand()%(4)) + 1;

          str=call_by_value(num);

          cout<<str<<endl;

      }

      else if(n==2)

      {

          int num = (rand()%(4)) + 1;

          str=call_by_reference(&num);

          cout<<str<<endl;

      }

      else

      cout<<"invalid input !"<<endl;

      cout<<"enter a value 1 and 2 for choice and -1 for exit :";

      cin>>n;

  }

  return 0;

}

Explanation:

Firstly, we declare three header files, then use namespace

Then, create the module of call by value and then call by reference.

Then we define the main() function in which we call both the modules.

You might be interested in
What is the name of a wireless network that allows phones and laptops to connect with pda's using bluetooth communications?
Jlenok [28]
Wireless Personal Area Netwrok (WPAN) or Personal Area Network (PAN)
4 0
4 years ago
A formula =A1+B2 is in cell D8. If you copy that formula to cell D9, what is the new formula in cell D9? A. '=A1+B2 B. '=A2+B3 C
Georgia [21]
It has to be B. Im sure of it.
6 0
4 years ago
Read 2 more answers
What's an e-mail server? An e-mail server is the computer to which the e-mail message is sent. An e-mail server is the e-mailing
umka2103 [35]

Answer:

An e-mail server is a specialized computer that stores, processes, and sends e-mails is the correct answer.

Explanation:

An email server is also called a mail transfer agent is a program that is responsible for delivering, storing and receiving the email by following standard email rules.

Types of Email server:

  • Outgoing mail servers.
  • Incoming mail servers.

The main purpose of the e-mail server is to stores the incoming mail and sends outgoing mails.

8 0
4 years ago
What does a software developer performed what are they duties
charle [14.2K]
As a software developer, your list of tasks can include:

• Reviewing current systems
• Presenting ideas for system improvements, including cost proposals
• Working closely with analysts, designers and staff
• Producing detailed specifications and writing the program codes
• Testing the product in controlled, real situations before going live
• Preparation of training manuals for users
• Maintaining the systems once they are up and running
8 0
4 years ago
Run net start "network access protection agent" on the windows 7 computers
aivan3 [116]
What is the question
3 0
4 years ago
Other questions:
  • Kendall receives an email stating that a leading computer company is giving away free computers, asking her to forward the email
    15·1 answer
  • Databases offer many security features including passwords to provide authentication, access levels to determine who can access
    15·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    11·1 answer
  • Choose the word that best completes this sentence. ____________ should cover every part of the worksite.
    10·2 answers
  • The intellectual property right that gives a creator control of his or her written work is known as what?
    9·1 answer
  • highlight the possible risks and problems that should be address during the implementation of information system process
    5·1 answer
  • Define the term editing​
    14·1 answer
  • _____ is responsible for packet forwarding. a. Transmission Control Protocol b. User Datagram Protocol c. Extensible Authenticat
    11·1 answer
  • (Display characters) Write a method that prints characters using the following header: public static void printChars(char ch1, c
    6·2 answers
  • What is Digital Citizen? It's one of my classes.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!