Question

I need help coding something in C++ from lecture

Create a separate file called mycode.cpp and write the following functions • my_add • Return sum of 2 numbers • my sub • Retu

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

Main FIle

mycode.cpp

#include <iostream>
#include "my_add.h"
#include "my_sub.h"
#include "my_div.h"
using namespace std;

// Function prototype (declaration)
int my_add(int, int);
int my_sub(int, int);
int my_div(int, int);
int main()
{
int x, y, sum,sub,div;
cout<<"Enters two numbers: ";
cin >> x >> y;

// Function call
sum = my_add(x, y);
cout << "Sum = " << sum <<endl;
  
sub = my_sub(x,y);
   cout << "Sub = " << sub<<endl;
  
   div = my_div(x,y);
   cout << "Div = " << div<<endl;
  
   return 0;
}

-----------------------------------------------------------------------------------------------------------------------

Save this file name my_add.h

#pragma once

int my_add(int x, int y);

-----------------------------------------------------------------------------------------------------------------------

Save this file name my_sub.h

#pragma once

int my_sub(int x, int y);

-----------------------------------------------------------------------------------------------------------------------

Save this file name my_div.h

#pragma once

int my_div(int x, int y);

-----------------------------------------------------------------------------------------------------------------------

// Function definition... Save this file name my_add.cpp

#include <iostream>

#include "my_add.h"

using namespace std;

int my_add(int x, int y)
{
int my_add;
my_add = x + y;

// Return statement
return my_add;
}

-----------------------------------------------------------------------------------------------------------------------

// Function definition... Save this file name my_sub.cpp

#include <iostream>

#include "my_sub.h"

using namespace std;

int my_sub(int x, int y)
{
int my_sub;
my_sub = x - y;

// Return statement
return my_sub;
}

-----------------------------------------------------------------------------------------------------------------------

// Function definition... Save this file name my_div.cpp

#include <iostream>

#include "my_div.h"

using namespace std;
int my_div(int x, int y)
{
int my_div;
my_div = (x + y)/2;

// Return statement
return my_div;
}

Add a comment
Know the answer?
Add Answer to:
I need help coding something in C++ from lecture Create a separate file called mycode.cpp and...
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
  • Please Use C++ for coding . . Note: The order that these functions are listed, do...

    Please Use C++ for coding . . Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all.cpp, input and output files for grading. Write a complete program that uses the functions listed below. Except for the printodd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention...

  • Description: Create a program called numstat.py that reads a series of integer numbers from a file...

    Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...

  • I am in C++ programming, I need help with this assignments. The answer in this assignments...

    I am in C++ programming, I need help with this assignments. The answer in this assignments when I look for it it doesn't work in my visual studios. Can you please help me? I hardly have C in the class, if I fail I will fail the whole class and repeat this class again.   The file named Random.txt contains a long list of random numbers. Download the file to your system, then write a program that opens the file, reads...

  • Note: The order that these functions are listed, do not reflect the order that they should...

    Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all .cpp, input and output files for grading. Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function...

  • C++ This week, you are to create two separate programs, first using a simple array and...

    C++ This week, you are to create two separate programs, first using a simple array and the second using a 2D-array (matrix). [Part 1] Write a program that accepts exactly ten (10) integer numbers from the user and stores them in an array. In a separate for-loop, the program then goes through the elements in the array to print back: (i) The sum of the 10 numbers, (ii) the minimum value from the 10 numbers, and (iii) the maximum value...

  • use MatLab to answer these questions 1. (10 points) Create an m-file called addup.m Use a...

    use MatLab to answer these questions 1. (10 points) Create an m-file called addup.m Use a for loop with k = 1 to 8 to sum the terms in this sequence: x(k) = 1/3 Before the loop set sumx = 0 Then add each term to sumx inside the loop. (You do not need to store the individual values of the sequence; it is sufficient to add each term to the sum.) After the loop, display sumx with either disp()...

  • Write a complete program that uses the functions listed below. Except for the printOdd function, main...

    Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...

  • Random accesses to a file. A file contains a formatted list of 9999 integers that are...

    Random accesses to a file. A file contains a formatted list of 9999 integers that are randomly generated in the range of [1,9999]. Each integer occupies one single line and takes 4 characters' space per line. Alternatively, you can think that each number takes 5 characters' space, four for the number and one for the newline character. Write a C++ program using the seekg() and seekp() functions to insert the numbers 7777 through 7781 between the 6000-th and 6001-st numbers...

  • Hi everyone! I need help on my Java assignment. I need to create a method that...

    Hi everyone! I need help on my Java assignment. I need to create a method that is called sumIt that will sum two values and will return the value.It should also invoke cubeIt from the sum of the two values. I need to change the currecnt program that I have to make it input two values from the console. The method has to be called sumIt and will return to the sum that will produce the cube of the sum...

  • I need help with a javascript assignment: Write a program called sum_number.js, that calculates the sum...

    I need help with a javascript assignment: Write a program called sum_number.js, that calculates the sum of the numbers contained in a string and displays the result. Use a string containing “2155” as your input value. For example, given the input , let num = “22”, I would sum 2 + 2 for a result of 4. The power is the amps at a given hour times the voltage at the same hour. Calculate the average power consumed for the...

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