Question

In: Computer Science

Download the attached file/s, copy and paste the code segment/s into your visual studio or any...

Download the attached file/s, copy and paste the code segment/s into your visual studio or any other C++ IDE and run it. You will have to implement a small intentional bug in your program and post it for other students to debug.

To be able to receive your full discussion points, you need to submit the following.

Following is your check list and rubric

      Attach your .cpp file/s with an implemented bug - 20pnts
      Describe what the code does in detail - 20pnts
      Debug at least one other program and submit your .cpp file - 40pnts (note what the bug was in comments)
      After running the debugged program, attach the screen shot of your output- 20pnts


// This program uses a function that returns a value.
#include <iostream>
using namespace std;

// Function prototype
int sum(int num1, int num2);

int main()
{
   int value1 = 20,   // The first value
       value2 = 40,   // The second value
       total;         // Holds the returned total

   // Call the sum function, passing the contents of
   // value1 and value2 as arguments. Assign the return
   // value to the total variable.
   total = sum(value1, value2);

   // Display the sum of the values
   cout << "The sum of " << value1 << " and "
        << value2 << " is " << total << endl;
   return 0;
}

/*********************************************************
*                          sum                          *
* This function returns the sum of its two parameters. *
*********************************************************/
int sum(int num1, int num2)
{
   return num1 + num2;
}

Solutions

Expert Solution

SOLUTION-

What the code does?

This program is used to calculate sum of two numbers using functions .

In this code we are using normal function which takes two number from main code . In the main code we have initialized value 1= 20 and value 2= 40 and then it will call the function sum and get the sum of two numbers and print ib the main .

There is no bug in the given code

CODE and OUTPUT Screenshots -


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

Download the attached file/s, copy and paste the code segment/s into your visual studio or any...
Download the attached file/s, copy and paste the code segment/s into your visual studio or any other C++ IDE and run it. You will have to implement a small intentional bug in your program // This program uses a function that returns a value. #include <iostream> using namespace std; // Function prototype int sum(int num1, int num2); int main() {    int value1 = 20,   // The first value        value2 = 40,   // The second value        total;         //...
R studio questions Write up your answers and paste the R code Copy and paste all...
R studio questions Write up your answers and paste the R code Copy and paste all plots generated. First create a sample drawn from a normal random variable. R has many distributions for which you can get probabilities and draw random numbers. We are going to use the normal. Go to help in R and type in rnorm. You will see a write up for functions associated with the normal distribution. dnorm is the density; pnorm is the probability distribution...
Copy the content of the source code into Visual Studio. Fill in the __BLANKS__ with proper...
Copy the content of the source code into Visual Studio. Fill in the __BLANKS__ with proper code and make it work! (HINT: you will be creating two files with this source code; one .cpp file and one .h file]. Please alter the code so that: YOUR first and last name appears as the fourth customer [Make up your balance and phone number.] Your Instructors first and last name appears as the fifth customer [Make up the balance and phone number.]...
4. Create a new project AccountPolymorphism and copy and paste the code from the attached AccountPolymorphism.cpp...
4. Create a new project AccountPolymorphism and copy and paste the code from the attached AccountPolymorphism.cpp file. Compile and run. You will see that it is not showing output for Base class pointer to base class object data, not showing derived class output completely(missing word "Saving" in the output) and not showing any output for Base class pointer to derived class object(Saving). Fix these issue and submit the output. // AccountPolymorphism.cpp : This file contains the 'main' function. Program execution...
Using R Studio Use the two iid samples. (You can copy and paste the code into...
Using R Studio Use the two iid samples. (You can copy and paste the code into R). They both come from the same normal distribution. X = c(-0.06, 1.930, 0.608 -0.133,0.657, -1.284, 0.166, 0.963, 0.719, -0.896) Y = c(0.396, 0.687, 0.809, 0.939, -0.381, -0.042, -1.529, -0.543, 0.758, -2.574, -0.160, -0.713, 0.311, -0.515, -2.332, -0.844, -0.942, 0.053, 0.066, 0.942, -0.861, -0.186, -0.947, -0.110, 0.634, 2.357, 0.201, -0.428, -1.661, 0.395) (a) Report 95% confidence interval for the mean of X. Should we...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
Directly copy the source code and paste into the Word file. Screenshot of running result must...
Directly copy the source code and paste into the Word file. Screenshot of running result must be presented. 1. (20 points) Write the “Hello, world!” program. 2. (30 points) Write a program to calculate the sum from -5 to10. Use the for loop to do the calculation. 3. (20 points) Write a complete C++ program that asks the user to enter the necessary information about the cylinder, calculate the volume in a function (named as calculate_vol, using reference to pass...
Please no copy and paste: Questions: 1. In your (supported) opinion, what, if any, is the...
Please no copy and paste: Questions: 1. In your (supported) opinion, what, if any, is the difference between "police community programs" and community policing? 2. What is meant by the term community policing and its relevance as regards serving the community? 3. Does community policing improve the relations between the police and members of a minority community?
Copy and paste the below code EXACTLY as shown into your Java environment/editor. Your task is...
Copy and paste the below code EXACTLY as shown into your Java environment/editor. Your task is to fill in the code marked as "...your code here...". A detailed explanation follows the code. import java.util.*; public class OddManOut {    public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How many random Integers to produce?"); int num = sc.nextInt();    ArrayList<Integer> randomInts = createRandomList(num); System.out.println("The random list is: "); System.out.println(randomInts);    removeOdds( randomInts ); System.out.println("The random list with only...
JAVA Copy the attached code into your IDE or an online compiler and test an additional...
JAVA Copy the attached code into your IDE or an online compiler and test an additional type with the generic class. Submit your code and execution display. JAVA The test cases for Integer and String is given in the code. Please add test cases for Character, Boolean and Double type etc. // A Simple Java program to show working of user defined // Generic classes    // We use < > to specify Parameter type class Test<T> {     //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT