Homework Help!

Hello Programmers! I am currently enrolled in school and use the book "starting with c++ 8th edition" and I have a homwork assignment from Chapter 7 which is "Introduction to classes and objects".

If you can please help me I would super appreciate it! Thanks in advance.



____________________________________________________________________________
Answer the following questions:

1. Complete the following code skeleton to declare a class called Date. The class should contain member variables and functions to store and retrieve the month, day, and year components of a date.

class Date
{
private:
public:

};

2. Describe the purpose of a constructor.


3. Assume the following is a constructor:

ClassAct::ClassAct(int x)
{ item = x; }

Define a ClassAct object called sally that passes the value 25 to the constructor.


4. What will the following program display on the screen?

#include <iostream>
using namespace std;
class Tank
{
private:
int gallons;
public:
Tank()
{ gallons = 50; }
Tank(int gal)
{ gallons = gal; }
int getGallons()
{ return gallons; }
};

int main()
{
Tank storage1, storage2, storage3(20);

cout << storage1.getGallons() << endl;
cout << storage2.getGallons() << endl;
cout << storage3.getGallons() << endl;
return 0;
}
5. Write a declaration for a structure named Location, with the following three double member variables: latitude, longitude, and height.

6. Write a declaration for a structure named City, which has a string member named cityName and a Location structure (from your previous question) member named position.

7. Write assignment statements that store the following information in destination.
city name: Tupelo
latitude: 34.28 // degrees north
longitude: -88.77 // degrees west
height: 361.0 // feet above sea level

Use the following structure declaration to answer questions 8-10.

struct Rectangle
{
int length;
int width;
};

8. Write a function that accepts the Rectangle structure defined above as its argument and displays the structure's contents on the screen.

9. Write a function that uses a Rectangle structure reference variable as its parameter and stores the user's input in the structure's members.

10. Write a function that returns a Rectangle structure. The function should create a local Rectangle variable, store the user's input in its members, and then return it.


Requirements:
1. Answer all questions.
2. You may use your online textbook to guide you.
3. Type your answers in this document.
4. Upload the single document to the class dropbox.
5. This assignment will take place for our Chapter 7 quiz. Maximum points 50 (5 pts each).

Deliverables:
• One (1) Word Document

Sample Output:
N/A


what was your question about the questions? What did you do already?
So in other words, you are asking us to answer all questions for you? Not a good idea, because asking homework questions in public but this is not a homework site.

You can ask a friend of yours or someone who knows C++ to do the questions for you.
Writing a "Date" class could be a surprisingly difficult task. This has potential to be a very good exercise.

Hint:
The main difficulty is that maintaining the class invariant is relatively complex. This is because there's no February 29th except on leap years. And that, e.g., March has 31 days and April only has 30.

A class implementation like
class Date { int month, day, year; ... };
Most likely isn't going to cut it.

You should do a little bit of research into how date and time facilities have been implemented historically -- Unix time would be a good starting point.
mbozzi wrote:
Writing a "Date" class could be a surprisingly difficult task.

It does not look like it, we only need to have some getter and setter functions and the question is done. However if there are additional requirements or one wants the class to be perfect yes this may be realistically difficult.
Topic archived. No new replies allowed.