Question

In: Computer Science

hello i have question in c++ language Q1: create a class called RightTriangleShape, and it has...

hello i have question in c++ language

Q1: create a class called RightTriangleShape, and it has data member called height which initialized to 3 by the constructor of the class. It has also the following function members:

  1. Void setHeight() to read, and set the height.
  2. Void getHeight() to print the value of height.
  3. void leftBottom_RTraingle(), prints shape a
  4. void leftTop_RTraingle(), prints shape b.
  5. void RightTop_RTraingle(), prints shape c.
  6. void RigtBottom_RTraingle(), prints shape d.

The functions from 3 to 6 have to print right-triangle shape of entered height.

Solutions

Expert Solution

#include <iostream>
using namespace std;
class RightTriangleShape
{
// Access specifier
public:

// Data Members
int height;
//Constructor and assigning height value to 3
RightTriangleShape()
{
height = 3;
}

// Setter
//Inputing value from user
void setHeight() {
cout << "Enter height value: ";
cin >> height;
if (height <= 0)
height = 3;
}
// Getter
//Printing the user entered value.
void getHeight() {
cout << "The height is " << height << "\n";
}
//Printing left bottom right triangle
void leftBottom_RTraingle() {
cout << "leftBottom_RTraingle:\n";
//Outer loop for counting rows from 1 to 5
for (int i = 1;i <= height;i++) {
//Inner loop for printing asterik values
for (int j = 1;j <= i;j++) {
cout << "* ";
}
cout << "\n";
}
}
void leftTop_RTraingle() {
cout << "leftTop_RTraingle:\n";
//This loop for counting rows from 5 to 1
for (int i = height;i >= 1;i--) {
//Inner loop for printing asterik values for i value
for (int j = 1;j <= i;j++) {
cout << "* ";
}
cout << "\n";
}
}
void RightTop_RTraingle() {
cout << "RightTop_RTraingle:\n";
//This loop for counting from 5 to 1
for (int i = height;i >= 1;i--) {
//This loop for printing spaces
for (int k = 1;k <= height - i;k++) {
//This will print two spaces
cout << " ";
}
//This loop for printing asterik
for (int j = 1;j <= i;j++) {
cout << "* ";
}
cout << "\n";
}
}
void RightBottom_RTraingle() {
//This loop for counting from 1 to 5
cout << "RightBottom_RTraingle:\n";
for (int i = 1;i <= height;i++) {
//This will print two spaces
for (int k = 1;k <= height - i;k++) {
cout << " ";
}
//This loop for printing asterik
for (int j = 1;j <= i;j++) {
cout << "* ";
}
cout << "\n";
}
}
};

int main()
{
//Creating objects
RightTriangleShape myObj,myobj1;
//With user input value
//If value is less than or equal to zero then value is set to 3
myObj.setHeight();
myObj.getHeight();
myObj.leftBottom_RTraingle();
myObj.leftTop_RTraingle();
myObj.RightTop_RTraingle();
myObj.RightBottom_RTraingle();

//Without user input value
myobj1.leftBottom_RTraingle();
myobj1.leftTop_RTraingle();
myobj1.RightTop_RTraingle();
myobj1.RightBottom_RTraingle();
return 0;
}

Sample Input and Output:

Enter height value: 7
The height is 7
leftBottom_RTraingle:
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
leftTop_RTraingle:
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
RightTop_RTraingle:
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
RightBottom_RTraingle:
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *

Sample Input and Output:

leftBottom_RTraingle:
*
* *
* * *
leftTop_RTraingle:
* * *
* *
*
RightTop_RTraingle:
* * *
* *
*
RightBottom_RTraingle:
*
* *
* * *

Sample Input and Output:

//If the value is less than zero or equal to zero then height will set to 3.
Enter height value: -1
The height is 3
leftBottom_RTraingle:
*
* *
* * *
leftTop_RTraingle:
* * *
* *
*
RightTop_RTraingle:
* * *
* *
*
RightBottom_RTraingle:
*
* *
* * *


COMMENT DOWN BELOW FOR ANY QUERIES AND,

LEAVE A THUMBS UP IF THIS ASNWER HELPS YOU.


Related Solutions

Hello, this question relates to a class I am taking called introduction to C++. I have...
Hello, this question relates to a class I am taking called introduction to C++. I have no experience writing programs and outside of learning out of a textbook, and studying on my own, have little understanding of logic. I have been assigned a problem that requires me to write a program for a Grocery Bill, where the consumer inputs the price for 5 items, that the program calculates the total with a 6% sales tax. I really am not sure...
I have a question about C++ programming Language class. I am confused with these terms and...
I have a question about C++ programming Language class. I am confused with these terms and what they are for. 1. Unix 2. Terminal 3. Git 4. CLOC 5. Linux Please explain each words and what's their jobs for C++. Also, if you know some good sources/websites, could you please provide me a link where I can learn how to use Unix, Terminal, Git, etc.
Using C# Create the “TestQuestion” class. It will have two class variables: 1) a question and...
Using C# Create the “TestQuestion” class. It will have two class variables: 1) a question and 2) the answer to that question. Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. There should be a constructor method. We will also have a “ToString” or “__str__” method, which will print the question followed by its answer. The constructor method has two parameters...
C++ program homework question 1 1. Create and implement a class called clockType with the following...
C++ program homework question 1 1. Create and implement a class called clockType with the following data and methods (60 Points.): Data: Hours, minutes, seconds Methods: Set and get hours Set and get minutes Set and get seconds printTime(…) to display time in the form of hh:mm:ss default and overloading constructor Overloading Operators: << (extraction) operator to display time in the form of hh:mm:ss >> (insertion) operator to get input for hours, minutes, and seconds operator+=(int x) (increment operator) to...
I have a quick question about this C ++ problem in my intro class. I have...
I have a quick question about this C ++ problem in my intro class. I have been able to get the first answer consistently when I test it, but my second seems to either be high or low no matter how I change it. Can you show me how you would do this problem with the setprecision(2) Paula and Danny want to plant evergreen trees along the back side of their yard. They do not want to have an excessive...
Hello this is for C++ language. I am currently stuck on creating my api for Day...
Hello this is for C++ language. I am currently stuck on creating my api for Day Trading Stocks. as follows I need an api for *//Function Signature * * parameter: * * Return Value: ** *// Write the following function taking in an integer vector (vector &prices) consisting of all prices, in chronological order, for an hypothetical instrument. Your function recommends the maximum profit an investor can make by placing AT MOST one buy and one sell order in the...
Hello, I am currently taking software design and analysis class and have a question about those...
Hello, I am currently taking software design and analysis class and have a question about those 3 in cpp, can you please help me? thank you - What is the complexity of pop()? push()? top()? size()? isEmpty()? - Write a C++ implementation of push() in a linked-chain implementation of stack - Write a C++ implementation of pop() in a linked-chain implementation of stack
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions:...
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions: getArea() setArea() printArea() Create classes to inherit from the base class Circle Square Rectangle Both implement the functions derived from the abstract base class AND must have private variables and functions unique to them like double Radius double length calculateArea() Use the spreadsheet info.txt read in information about the circle, rectangle, or square text file: circle   3.5   square   3   rectangle   38   36 circle   23  ...
LANGUAGE: JAVA Create a New Project called YourLastNameDomainName. Write a DomainName class that encapsulates the concept...
LANGUAGE: JAVA Create a New Project called YourLastNameDomainName. Write a DomainName class that encapsulates the concept of a domain name, assuming a domain name has a single attribute: the domain name itself. Include the following: - Constructor: accepts the domain name as an argument. - getDomain: an accessor method for the domain name field. - setDomain: a mutator method for the domain name field. - prefix: a method returning whether or not the domain name starts with www. - extension:...
C++ Coding Exercise (If... Else) Hello All, I know this question has been asked before, but...
C++ Coding Exercise (If... Else) Hello All, I know this question has been asked before, but I was unable to run any of the programs that were posted and I'm stuck. I would like to see an explanation with the code and exactly how to add a .txt file to the program through VS 2019, if possible. LAB: Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT