Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Homework Ch. 5- Pattern Display 30 points First design, then write a program tha

ID: 3906099 • Letter: H

Question

Homework Ch. 5- Pattern Display 30 points First design, then write a program that prompts the user for a positive integer no greater than 12. The program should then use two nested loops to display two triangles on the screen and simultaneously writes (outputs) two triangles to a file called triangles.txt using the character. The number entered by the user will be the height and width of the triangle (at its base). Here is an example of the program's output: Enter the height of the triangle: 3d Please submit the following: 1. Your flowchart 2. Your source code, a.cpp file: 3. The program output 4. The triangles.txt file Points will be given based on the following requirements: Program Specifications/Correctness . Readability Documentation . Code Efficiency . Assignment Specifications

Explanation / Answer

#include <iostream>
#include <fstream>

using namespace std;

int main() {
   cout << "Enter the height of the triangle: ";
   int n;
   cin >> n;
   ofstream out("triangles.txt");
   for(int i = 0; i < n; ++i) {
       for(int j = 0; j <= i; ++j) {
           out << "*";
       }
       out << endl;
   }
   out << endl;
   for(int i = n-1; i >= 0; --i) {
       for(int j = 0; j <= i; ++j) {
           out << "*";
       }
       out << endl;
   }
   out.close();  
   return 0;
}