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...
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...
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  ...
Needed in C++ In this assignment, you are asked to create a class called Account, which...
Needed in C++ In this assignment, you are asked to create a class called Account, which models a bank account. The requirement of the account class is as follows (1) It contains two data members: accountNumber and balance, which maintains the current account name and balance, respectively. (1) It contains three functions: functions credit() and debit(), which adds or subtracts the given amount from the balance, respectively. The debit() function shall print ”amount withdrawn exceeds the current balance!” if the...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
Create a C# Application. Create a class object called “Employee” which includes the following private variables:...
Create a C# Application. Create a class object called “Employee” which includes the following private variables: firstN lastN idNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: constructor properties CalcPay(): Calculate the regular pay and overtime pay. Create...
Create a file called grocery.ts. It should have a definition of a class with the obvious...
Create a file called grocery.ts. It should have a definition of a class with the obvious name Grocery. The class should have some basic attributes such as name, quantity, etc. Feel free to add any other attributes you think will be necessary. Add few grocery items to an array of groceries, such as milk, bread, and eggs, along with some quantities (i.e. 3, 6, 11). Display these grocery items as HTML output. The output of this assignment will be grocery.ts...
In java language how would I write the following? Create an array called “boyNames” and store...
In java language how would I write the following? Create an array called “boyNames” and store all names from the BoyNames.txt file Similarly, create an array called “girlsNames” and store all names from the GirlNames.txt file Create a text menu that allowing users to:          1. Enter a name and the application must display a message indicating if the name is   among the most popular (found on either array) If the name is found, tell the user if it is a boy’s...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT