#1. (Submit cpp file)
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
#1. (Submit cpp file)
Create a class called Flower. Add one member variable color. Add only one getter function for the color. The get function returns color. Implement a constructor that expects color value and assigns it to the member variable.
Create a subclass of Flower named Rose. The Rose class has one member variable name. Add a constructor which expects color and name. Pass color to the base constructor and set name to it's member variable.
Write a program that has an array of 3 Flowers, and an array of 3 Roses. Feel free give the name and color to the flower as your choice. Use loops to print out the array properties to the terminal screen.
Note:
● Add comments to the top of the code stating your name and assignment #.
● If your code has any syntax errors and does not compile, it will be given at most 50% of the total score.
● It is a good practice to implement this current assignment into multiple files .h, .cpp. The point will not be deducted if you implement everything in a single .cpp file.
● Always use proper formatting and follow good programming practices.
Source Code
#include<iostream>
using namespace std;
class Flower
{
private:
string color;
public:
Flower (string flowerColor)
{
color = flowerColor;
}
string getColor ()
{
return color;
}
};
class Rose : public Flower
{
private:
string name;
public:
Rose (string flowerColor, string roseName) : Flower (flowerColor)
{
name = roseName;
}
string getName ()
{
return name;
}
};
int main ()
{
Flower flowers [3] = {Flower{"Lavender"}, Flower{"Whiskey Red"}, Flower{"Sky
Blue"}};
Rose roses [3] = {Rose{"Pink","Rosa"}, Rose{"White","Fiona"},
Rose{"Orange","Amber"}};
cout << "*** Welcome to Floral Garden *** " << endl;
cout << "\nColor of Flowers" << endl;
cout << "--------------------" << endl;
for (int i = 0; i < 3; i++)
cout << flowers [i].getColor () << endl;
cout << "\nRose Name\tColor" << endl;
cout << "--------------------" << endl;
for (int i = 0; i < 3; ++i)
{
cout << roses [i].getName () << "\t\t" << roses [i].getColor () << endl;
}
return 0;
}
#2. (Submit cpp. file)
Write a program that draws a square-like box by using the character 'X' as examples below. The program must use the while loop to draw a box as examples below. The program must prompt a user for an integer larger than 2. The program must re-prompt until a valid input is entered. The user will then be used to set the size of the output. If a user inputs an even value, the program will increase it by one before drawing the box
Example 1:
Input 3:
Output: XXX
XXX
XXX
Example 2:
Input: 4
Output: XXXXX
XXXXX
XXXXX
XXXXX
Source Code:
#include <iostream>
using namespace std;
int main ()
{
int n;
cout << "Input: ";
cin >> n; //asking for input
while (n <= 2) //asking for input until n is less than 2
{
cout << "Please try again!" << endl;
cout << "Input: ";
cin >> n;
}
if (n%2 == 0) // if n is even
n++; //increment n
for (int i=0;i<n;i++) //printing the pattern using n
{
for (int j=0;j<n;j++)
{
cout << "X";
}
cout<<endl;
}
}
#2. (Fill in blank)
2022-07-28