Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an analysis sheet for the code below. It must include a visual representation. - - - - - - - - - - -

Create an analysis sheet for the code below. It must include a visual representation.
----------------
TriangularVertices.h
----------------
#ifndef _TRIANGULARVERTICES
#define _TRIANGULARVERTICES
class TriangularVertices {
public:
void printTriangle(int rows);
private:
void printNumbersRow(int row);
void printSlashesRow(int row);
void printSpacesBefore(int totalRows, int currentRow);
int calculateStartNumber(int row);
};
#endif
-------------------
TriangularVertices.cpp
-------------------
#include
#include
class TriangularVertices {
public:
void printTriangle(int rows);
private:
void printNumbersRow(int row);
void printSlashesRow(int row);
void printSpacesBefore(int totalRows, int currentRow);
int calculateStartNumber(int row);
};
void TriangularVertices::printTriangle(int rows){
for (int i =1; i <= rows; ++i){
printSpacesBefore(rows, i);
printNumbersRow(i);
std::cout << std::endl;
if (i != rows){
printSpacesBefore(rows, i);
printSlashesRow(i);
std::cout << std::endl;
}
}
}
void TriangularVertices::printNumbersRow(int row){
int startNumber = calculateStartNumber(row);
for (int i =0; i < row; ++i){
std::cout << std::setw(2)<< startNumber + i;
if (i < row -1)
std::cout <<"";
}
}
void TriangularVertices::printSlashesRow(int row){
std::cout << std::setw(1);
for (int i =0; i < row; ++i){
std::cout <<"/\\";
if (i < row -1)
std::cout <<"";
}
}
void TriangularVertices::printSpacesBefore(int totalRows, int currentRow){
int spaces =(totalRows - currentRow)*2;
for (int i =0; i < spaces; ++i){
std::cout <<"";
}
}
int TriangularVertices::calculateStartNumber(int row){
return row *(row -1)/2+1;
}
-----------------
Source.cpp
-----------------
#include "TriangularVertices.h"
#include
int main(){
TriangularVertices tv;
int rows;
do {
std::cout << "How many triangular vertices rows do you want to display? Enter an integer from 1 to 13: ";
std::cin >> rows;
if (rows <1|| rows >13)
std::cout << "Invalid input. Please enter a number from 1 to 13.
";
} while (rows <1|| rows >13);
tv.printTriangle(rows);
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions