Write a program that computes and prints the sum of integers from A to B. Create
ID: 667148 • Letter: W
Question
Write a program that computes and prints the sum of integers from A to B. Create an appropriate class Summer that has a sum method that takes the range of numbers (A and B) from the user and returns the sum. Create a second class (SummerTester) with a main method to construct two objects of the Summer class and call the sum method to print out the result. For example: assume A = 1 and B = 100, the Sum will be: 1 + 2 + 3 + 4 + . . . + 100 Write a program that computes and prints the sum of integers from A to B. Create an appropriate class Summer that has a sum method that takes the range of numbers (A and B) from the user and returns the sum. Create a second class (SummerTester) with a main method to construct two objects of the Summer class and call the sum method to print out the result. For example: assume A = 1 and B = 100, the Sum will be: 1 + 2 + 3 + 4 + . . . + 100 Write a program that computes and prints the sum of integers from A to B. Create an appropriate class Summer that has a sum method that takes the range of numbers (A and B) from the user and returns the sum. Create a second class (SummerTester) with a main method to construct two objects of the Summer class and call the sum method to print out the result. For example: assume A = 1 and B = 100, the Sum will be: 1 + 2 + 3 + 4 + . . . + 100Explanation / Answer
#include <iostream>
int addNumbers(int array[], int numberOfNumbers)
int sum = 0;
// for loop
for (int i = 0; i<= numberOfNumbers; i++)
{
sum = sum + i;
}
System.out.println(sum);
int Main()
{
int numberOfNumbers = 0;
int array[20]
cout << "Welcome to the Summer!" << endl;
cout << "Enter numbers one at a time, when done enter -1" << endl;
int number = 0;
while (number != -1)
{
if (cin >> number)
{
if (number != -1)
{
array[numberOfNumbers] = number;
numberOfNumbers++;
}
{
int sum = addNumbers(array, numberOfNumbers);
cout << "Total: " << sum << endl;
}
{
return 0
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.