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...
Language C++ Student-Report Card Generator: create a class called student and class called course. student class...
Language C++ Student-Report Card Generator: create a class called student and class called course. student class this class should contain the following private data types: - name (string) - id number (string) - email (s) - phone number (string) - number of courses (int) - a dynamic array of course objects. the user will specify how many courses are there in the array. the following are public members of the student class: - default constructor (in this constructor, prompt the...
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.
C# Language Create a class called evaluateValue that declares 3 integer class variables: zeroValue, positiveValue and...
C# Language Create a class called evaluateValue that declares 3 integer class variables: zeroValue, positiveValue and negativeValue. These should be declared as public and you should not use automatic properties to declare them. Your class should have a constructor that takes one integer argument. In the constructor you will code if statements to set one of the three class variables (indicators) to 1 if the number sent to the constructor is either equal to zero, negative, or positive. In the...
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...
its java language. 1. Create a class called Car. A Car has instance variables, constructor parameters,...
its java language. 1. Create a class called Car. A Car has instance variables, constructor parameters, setters, and getters for “year manufactured” and “make” and “model” (e.g. 2016 Honda Civic) 2. Create a class called CarLot which has an array of 5 Car references. There are two constructors: (a) One constructor takes no parameters and simply populates the array with these cars: cars[0] = new Car(2016, “honda”, “civic”); cars[2] = new Car(2017, “Lamborghini”, “aventador”); cars[3] = new Car(2000, null, “caravan”);...
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
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT