Question

In: Computer Science

Using c++, write a program that will display your name as a void function then will...

Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions:


a. to compute for the sum of two numbers (n1, n2) using function.

Solutions

Expert Solution

CODE

#include <iostream>
using namespace std;

//Void Function
void dispName(){
//Display Name
cout<<"John\n";
//Void function do not return any value
}
//Return value of function Sum is Integer
int sum(int n1,int n2){
//return n1+n2
return(n1+n2);
}

int main()
{
//Calling
dispName();
// Taking input n1,n2
int n1,n2,result;
cout<<"Enter Number 1: ";
cin>>n1;
cout<<"Enter Number 2: ";
cin>>n2;
//Calling
result=sum(n1,n2);
//Print the result
cout<<"Result: "<<result;
return 0;
}

CODE SNIPPET

OUTPUT


Related Solutions

Write a C++ program to display toy name
Write a C++ program to display toy name
Program Description Write and test a MASM program to perform the following tasks: Display your name...
Program Description Write and test a MASM program to perform the following tasks: Display your name and program title on the output screen. Display instructions for the user. Prompt the user to enter three numbers (A, B, C) in descending order. Calculate and display the sum and differences: (A+B, A-B, A+C, A-C, B+C, B-C, A+B+C). Display a closing message. Program Requirements The program must be fully documented and laid out according to the CS271 Style Guide. This includes a complete...
Write a program that accepts user’s name, password and address and display them back using the...
Write a program that accepts user’s name, password and address and display them back using the format “Hi, I am user’s name. I live at user’s address.”. Restrictions: ▪ Use only three variables. ▪ Make sure you support spaces.
C++ PLEASE Write a new program called Lab15A Write a void function named fillArray that receives...
C++ PLEASE Write a new program called Lab15A Write a void function named fillArray that receives an array of 10 integers as a parameter and fills the array by reading the values from a text file (Lab15A.txt). It should also print the values of the array all on the same line, separated by spaces. Write an int function named findLast that receives an array of 10 integers as a parameter and returns the last negative number in the array. Write...
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
ACTIVITY #1: Defining Strings √ Write an assembly program that display your name, your id, and...
ACTIVITY #1: Defining Strings √ Write an assembly program that display your name, your id, and your college name on the screen. √ Remember: the format of the assembly program should be like this. TITLE your title (FileName.asm) .MODEL FLAT .386 .STACK 64 .DATA str1 DB "My name: Essam Alnatsheh",13,10,'$' .CODE main PROC mov ax,@data mov ds,ax mov ah,09h mov dx, offset str1 int 21h ​mov ah,4Ch​​ ; terminate process ​mov al,0​​ ; return code ​int 21h main ENDP END...
Write a C++ program using separate void which asks the user to input side of a...
Write a C++ program using separate void which asks the user to input side of a square, radius of a circle , height and base of a triangle and finds the area of squares, circles and triangles. Then using main function display the area of square, circle and triangle
Write a rudimentary spreadsheet program using C++. Display a grid of cells with columns A through...
Write a rudimentary spreadsheet program using C++. Display a grid of cells with columns A through H and rows 1 through 20. Accept input in the first row of the screen. The commands are of the form column row entry, where entry is a number, a cell address preceded by a plus (e.g., +A5), a string, or a function preceded by an at sign, @. The functions are: max, min, avg, and sum. During execution of your program, build and...
C++ Write the C++ code for a void function that prompts the user to enter a...
C++ Write the C++ code for a void function that prompts the user to enter a name, and then stores the user's response in the string variable whose address is passed to the function. Name the function getName.
Description: Write and test a MASM program to perform the following tasks: 1. Display your name...
Description: Write and test a MASM program to perform the following tasks: 1. Display your name and program title on the output screen. 2. Display instructions for the user. 3. Prompt the user to enter two numbers. 4. Calculate the sum, difference, product, (integer) quotient and remainder of the numbers. 5. Display a terminating message. Requirements: 1. The main procedure must be divided into sections:  introduction  get the data  calculate the required values  display the results...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT