Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Definition (in C++ language): Build a Date class and a main function to test it. Specifications We have provided the interface (declaration) for the

Problem Definition (in C++ language):

Build a Date class and a main function to test it.

Specifications

We have provided the interface (declaration) for the Date class: it is our "contract" with you: you have to implement everything it describes. The comments in the provided interface should be sufficient for you to understand the project (do not delete these comments in your Date declaration), without the need of any further documentation. But of course, as always, you can ask us any questions you may have on Campuswire.

Note: Placing the error messages into the constructors like is not necessarily a good way to handle constructor errors, but until you learn about exceptions in CS 14, it's the best we can do.

Private Member Functions

The member functions declared private, isLeap, daysPerMonth, name, number, are helper functions - member functions that will never be needed by a user of the class, and so do not belong to the public interface (which is why they are "private"). They are, however, needed by the interface functions (public member functions), which use them to test the validity of arguments and construct valid dates. For example, the constructor that passes in the month as a string will call the number function to assign a value to the unsigned member variable month.

isLeap: The rule for whether a year is a leap year is:

  • (year % 4 == 0) implies leap year
  • except (year % 100 == 0) implies NOT leap year
  • except (year % 400 == 0) implies leap year

So, for instance, year 2000 is a leap year, but 1900 is NOT a leap year. Years 2004, 2008, 2012, 2016, etc. are all leap years. Years 2005, 2006, 2007, 2009, 2010, etc. are NOT leap years.

Output Specifications

Read the specifications for the print function carefully. The only cout statements within your Date member functions should be:

  1. the "Invalid Date" warnings in the constructors
  2. in your two print functions

Required Main Function

You must use the provided main function and global function getDate as they are here. You may not change these functions at all to pass the tests in submit mode.

//

#include #include #include #include #include #include #include #include #include

using namespace std;

void readData(const string&, vector&, vector&); double interpolation(double, const vector&, const vector&); bool isOrdered(const vector&); void reorder(vector&, vector&);

int main() { string userInputFile; vector path; vector lift; bool validInput = true; double pathInput; double liftCoefficient;

cin >> userInputFile;

readData(userInputFile, path, lift);

cout << endl << endl;

if(path.empty()) { while(path.empty() || (path.size() != lift.size())) { cout << "Enter a different file" << endl; cin >> userInputFile; readData(userInputFile, path, lift); } } while(!isOrdered(path)) { reorder(path, lift); }

while(validInput) { cout << "Enter flight path angle" << endl << "Enter 1337 to break the loop and exit" << endl; cout << "Do not enter a string value, only doubles or ints" << endl << endl; cin >> pathInput; if(pathInput == 1337) { validInput = false; } else if(pathInput < path.at(0) || pathInput > path.at(path.size() - 1)) { cout << "Enter a value in the data's range" << endl; cin >> pathInput; } else { liftCoefficient = interpolation(pathInput, path, lift); cout << "The lift coefficient for the flight path angle " << pathInput << " is: " << liftCoefficient << endl; } }

return 0; }

void readData(const string& fileInput, vector& path, vector& lift) { ifstream dataFile; double temp1 = 0.0; double temp2 = 0.0;

dataFile.open(fileInput.c_str());

if(!dataFile.is_open()) { cout << "Error opening "; cout << "tunnel11.txt" << endl; exit(1); } while(dataFile >> temp1) { path.push_back(temp1); //dataFile takes in temp1 then pushes into path vector dataFile >> temp2; lift.push_back(temp2); //start reading again after whitespace, then push into lift }

dataFile.close(); }

double interpolation(double b, const vector& path, const vector& lift) { for(unsigned i = 0; i < path.size(); i++) { if(path.at(i) == b) { return lift.at(i); } } for(unsigned i = 0; i < path.size(); i++) { if(b > path.at(i)) { return lift.at(i) + (b - path.at(i)) / (path.at(i+1) - path.at(i)) * (lift.at(i+1) - lift.at(i)); } } return 0; } //f(b) = f(a) + (b - a)/(c - a)(f(c) - f(a))

bool isOrdered(const vector& path) { if(!path.empty()) { for(unsigned i = 0; i+1 < path.size(); i++) { if(path.at(i) > path.at(i+1)) { return false; } } } return true; }

unsigned findMin(const vector& v, unsigned start) { unsigned small = start; for(unsigned i = start + 1; i < v.size(); i++) { if(v.at(i) < v.at(small)) { small = i; } } return small; }

void reorder(vector &path, vector &lift) { sort(path.begin(), path.end()); sort(lift.begin(), lift.end()); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions