SA#7: Write a class declaration for a class named Circle , which has the data me
ID: 3540557 • Letter: S
Question
SA#7: Write a class declaration for a class named Circle, which has the data member radius, a double, and the following member functions: setRadius and getArea. Write the procedures for setRadius and getArea as inline functions. (5pts)
WRITE YOUR ANSWER:
Use the following Car structure declaration to answer short answer questions 8 - 10.
struct Car
{
string make, model;
int year;
double cost;
// Constructors
Car( )
{ make = model = %u201C %u201C; year = cost = 0; }
Car(string mk, string md, int yr, double c)
{ make = mk; model = md; year = yr; cost = c; }
};
SA#8: Define an array named collection that holds 40 Car structures. (2pts)
WRITE YOUR ANSWER:
SA#9: Define an array named forSale that holds 25 Car structures. Initialize the first three elements with the following data: (6pts) Make Model Year Cost
Honda Accord 2004 $11,000
Ford Taurus 2006 $21,000
Jeep Wrangler 2007 $24,000
WRITE YOUR ANSWER:
SA#10: Write a loop that will step through the array you defined in short answer question#9 above, displaying the contents of each element. (10pts)
WRITE YOUR ANSWER:
SA#3: Rewrite the following code, replacing the do-while loop with a while loop. When you do this you will no longer need an if statement. (5pts)
int number;
cout <<%u201DEnter an even number: %u201C;
do
{
cin>> number;
if (number % 2 != 0)
cout << %u201CNumber must be even. Reenter number: %u201C;
} while (number % 2 != 0);
WRITE YOUR ANSWER:
SA#4: Convert the following for loop to a while loop: (5pts)
for (int x=50; x >0; x--)
{
cout<< x << %u201C seconds to go. %u201D;
}
WRITE YOUR ANSWER:
SA#5: Write a function named getNumber, which uses a reference parameter to accept an integer argument. The function should prompt the user to enter a number in the range of 1 through 25. The input should be validated and stored in the parameter variable. (5pts)
WRITE YOUR ANSWER:
Write a class declaration for a class named Circle, which has the data member radius, a double, and the following member functions: setRadius and getArea. Write the procedures for setRadius and getArea as inline functions. Use the following Car structure declaration to answer short answer questions 8 - 10.Explanation / Answer
public class Circle {private int radius; private Point point;
public Circle() { point = new Point(0, 0); radius = 1; }
public Circle(int x, int y, int r) { point = new Point(x, y); radius = r; }
public int getRadius() { return radius; }
public double getArea() { return Math.PI * radius * radius; }
public double getPerimeter() { return 2 * Math.PI * radius; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.