Question

In: Computer Science

In C++ Complete the template program. ADD to your c++ program as a comment the PARTIAL...

In C++ Complete the template program.

ADD to your c++ program as a comment

the PARTIAL output from executing your

program - Only copy the last 6 lines of output.

There is no input data for this problem.

// Find Pythagorean triples using brute force computing.


#include <iostream>


using std::cout;


using std::endl;


int main()
{
int count = 0; // number of triples found


long int hypotenuseSquared; // hypotenuse squared


long int sidesSquared; // sum of squares of sides


cout << "Side 1\tSide 2\tSide3" << endl;


// side1 values range from 1 to 500


/* Write a for header for side1 */

{

// side2 values range from current side1 to 500


/* Write a for header for side2 */

{

// hypotenuse values range from current side2 to 500


/* Write a for header for hypotenuse */

{

// calculate square of hypotenuse value


/* Write a statement to calculate hypotenuseSquared */

// calculate sum of squares of sides


/* Write a statement to calculate the sum of the sides Squared */

// if (hypotenuse)^2 = (side1)^2 + (side2)^2,

// Pythagorean triple

if ( hypotenuseSquared == sidesSquared )

{

// display triple

cout << side1 << '\t' << side2 << '\t' << hypotenuse << '\n';

count++; // update count

} // end if
} // end for
} // end for
} // end for

// display total number of triples found

cout << "A total of " << count << " triples were found." << endl;

return 0; // indicate successful termination

} // end main

Solutions

Expert Solution

Thanks for the question.


Here is the completed code for this problem.

Thanks


===========================================================================

#include <iostream>
using std::cout;
using std::endl;

int main()
{
int count = 0; // number of triples found

long int hypotenuseSquared; // hypotenuse squared
long int sidesSquared; // sum of squares of sides
cout << "Side 1\tSide 2\tSide3" << endl;

// side1 values range from 1 to 500
/* Write a for header for side1 */
for(int side1=1; side1<=500;side1++)
{

// side2 values range from current side1 to 500

for(int side2=side1; side2<=500;side2++)
/* Write a for header for side2 */

{

// hypotenuse values range from current side2 to 500

for(int hypotenuse=side2; hypotenuse<=500;hypotenuse++)
/* Write a for header for hypotenuse */
{

// calculate square of hypotenuse value
/* Write a statement to calculate hypotenuseSquared */
hypotenuseSquared=hypotenuse*hypotenuse;
// calculate sum of squares of sides
   sidesSquared = side1*side1 + side2*side2;

/* Write a statement to calculate the sum of the sides Squared */
// if (hypotenuse)^2 = (side1)^2 + (side2)^2,
// Pythagorean triple
if ( hypotenuseSquared == sidesSquared )
{
// display triple
cout << side1 << '\t' << side2 << '\t' << hypotenuse << '\n';
count++; // update count
} // end if
} // end for
} // end for
} // end for
// display total number of triples found
cout << "A total of " << count << " triples were found." << endl;
return 0; // indicate successful termination
} // end main


Related Solutions

Reversing Digits - Complete the template program in C++ (Be Original) // reverseNumber.cpp // Reverse the...
Reversing Digits - Complete the template program in C++ (Be Original) // reverseNumber.cpp // Reverse the digits of a number. #include <iostream> using std::cin; using std::cout; using std::endl; #include <iomanip> using std::setw; /* Write prototype for reverseDigits */ // STUDENT WRITES CODE HERE int main() { int number; // input number cout << "Enter a number between 1 and 9999: "; cin >> number; cout << "The number with its digits reversed is: "; // find number with digits reversed...
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file...
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list functionality. The functions header file is also given. Complete the functions of the header file linked_list.h below. ========================================================= // listmain.cpp #include "Linked_List.h" int main(int argc, char **argv) {      float           f;      Linked_List *theList;      cout << "Simple List Demonstration\n";      cout << "(List implemented as an Array - Do...
Complete the attached program by adding the following: a) add the Java codes to complete the...
Complete the attached program by adding the following: a) add the Java codes to complete the constructors for Student class b) add the Java code to complete the findClassification() method c) create an object of Student and print out its info in main() method of StudentInfo class. * * @author * @CS206 HM#2 * @Description: * */ public class StudentInfo { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application...
C++ UML is required for this program. Partial credit will be given in the program if...
C++ UML is required for this program. Partial credit will be given in the program if you comment your code and I can see you had the right idea even if it is not working correctly. It is better to write comments for parts of the program you cannot figure out than to write nothing at all. Read the directions for the program carefully before starting. Make sure and ask if the directions are unclear. The Rent-a-Pig company rents guinea...
Please write a C++ program. Please rewrite your Array (including the operator overloading) into a template....
Please write a C++ program. Please rewrite your Array (including the operator overloading) into a template. And rewrite your main function to test your template for integer array and double array. Following is my complete code: #include <iostream> using namespace std; class Array { private: // Pointer to memory block to store integers int* data; // Maximum size of memory block int cap; // Stores number of integers in an array int num; public: // Constructor Array(int size); // Default...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
Write a C++ function template to add two inputs and return their result. Make exceptions for...
Write a C++ function template to add two inputs and return their result. Make exceptions for Characters (such that sum of two characters is a character associated with sum of their ASCII) and String (such that sum of two strings is their concatenation)
The code must be under c++ program. For your Double and Integer classes add a default...
The code must be under c++ program. For your Double and Integer classes add a default constructor that sets the value to 0.0 and 0 respectively. Then add the following overloaded constructors Double class A Double argument A primitive double An Integer class Integer class An Integer class A primitive int Each of these constructors should set the data section of the class to the value being passed to it. In addition to the overloaded constructors add the following overloaded...
Program Zeus:    Complete the Count Vowels program (Count Vowels.cpp template provided at the end) to include two...
Program Zeus:    Complete the Count Vowels program (Count Vowels.cpp template provided at the end) to include two user defined functions (which you will write!). Code lenguage is C++ bool isVowel (char c)       // returns true if c is a vowel and false otherwise int countVowels (string s) // returns the number of vowels in s. You can access each character of s by using s.at(i) where i ranges from 0 to s.length()-1. countVowels () should call isVowel (s.at(i)) to check...
''' string_funcs ========== Complete the following functions. You MUST, MUST, MUST add: 1) a doc comment...
''' string_funcs ========== Complete the following functions. You MUST, MUST, MUST add: 1) a doc comment in the proper location for EACH function that describes the basic purpose of the function. 2) AT LEAST 3 doc test comments in EACH function that: * test that the function does what it is supposed to do * tests that it does what it's supposed to do with odd inputs * tests "edge" cases (numbers at, just above, just below min/max, empty strings,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT