1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
natulia [17]
3 years ago
6

Date Class Constructor – assigns fields to appropriate formal parameter – using the setters so error checking will occur. The co

nstructor with no formal parameters should have no statements in the body of the function. Accessors – return the appropriate fields Setters setMonth – assigns the field to the formal parameter. Error checks the formal parameter to make sure it is a valid month number. If it isn’t a valid month, it sets the month to 1. setDay – assigns the field to the formal parameter. Error checks to make sure the day being passed in is a valid day for the month the object has (ex: January can only be 1-31). You do NOT have to check for leap year – just make sure February is 1-29. If the day is invalid, it sets the day to be 1 setYear – assigns the field to the formal parameter. Error checks the formal parameter to make sure it is not negative. If it is it sets the year to be 1900. toString – creates a string in the format M/D/Y and returns it. The following allows you to concatenate a string with an integer. Use this information to create and return the string in the format M/D/Y. string ans = to_string(month) + "/"; Date -day: int -month: int -year: int +Date() +Date(month:int, day:int, year:int) +getMonth(): int +getDay(): int +getYear():int +setMonth(month:int):void +setDay(day:int) :void +setYear(year:int) :void +toString():string

Computers and Technology
1 answer:
lara31 [8.8K]3 years ago
4 0

Answer:

Check the explanation

Explanation:

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

#include "Date.h"

#include "Person.h"

using namespace std;

const int MAXSIZE = 50;

// Prototypes go here

int loadArray(string fileName, Person students[]);

void sortByName(Person students[], int numE);

void printStudentReport(Person students[], int numE);

int main()

{

Person students[MAXSIZE];

int numE;

string fileName;

cout << "Enter the file name: ";

cin >> fileName;

numE = loadArray(fileName, students);

cout << endl;

cout << "Before Sort: " << endl;

printStudentReport(students, numE);

sortByName(students, numE);

cout << endl;

cout << "After Sort: " << endl;

printStudentReport(students, numE);

return 0;

}

int loadArray(string fileName, Person students[]){

ifstream in;

in.open(fileName.c_str());

if(in.fail())

return -1;

int n=0;

string fname, lname;

int month, day, year;

while(!in.eof()){

in>>fname>>lname>>month>>day>>year;

students[n] = Person(fname, lname, Date(month, day, year));

n++;

}

return n;

}

void sortByName(Person students[], int numE){

for(int i=0; i<numE; i++){

for(int j=i+1; j<numE; j++){

if(students[i].getLastName()>students[j].getLastName()){

Person temp = students[i];

students[i] = students[j];

students[j] = temp;

}

}

}

}

void printStudentReport(Person students[], int numE){

for(int i=0; i<numE; i++){

cout<<students[i].getLastName()<<", "<<students[i].getFirstName()<<"\t\t"<<students[i].getDateofBirth().toString()<<endl;

}

}

Person.h

#include<iostream>

#include<string>

using namespace std;

#include "Date.h"

#ifndef PERSON_H

#define PERSON_H

class Person{

private:

string firstName;

string lastName;

public:

Date dateOfBirth;

Person();

Person(string firstName, string lastName, Date dob);

string getFirstName();

string getLastName();

Date getDateofBirth();

void setFirstName(string fname);

void setLastName(string lname);

void setDateOfBirth(Date dob);

void setDateOfBirth(int month, int day, int year);

};

#endif

Person.cpp

#include "Person.h"

Person::Person(){

firstName = "";

lastName = "";

}

Person::Person(string firstName, string lastName, Date dob){

this->firstName = firstName;

this->lastName = lastName;

setDateOfBirth(dob.getMonth(), dob.getDay(), dob.getYear());

}

string Person::getFirstName(){

return firstName;

}

string Person::getLastName(){

return lastName;

}

Date Person::getDateofBirth(){

return dateOfBirth;

}

void Person::setFirstName(string fname){

firstName = fname;

}

void Person::setLastName(string lname){

lastName = lname;

}

void Person::setDateOfBirth(Date dob){

setDateOfBirth(dob.getMonth(), dob.getDay(), dob.getYear());

}

void Person::setDateOfBirth(int month, int day, int year){

dateOfBirth.setMonth(month);

dateOfBirth.setDay(day);

dateOfBirth.setYear(year);

}

Date.h

#include<iostream>

#include<string>

using namespace std;

#ifndef DATE_H

#define DATE_H

class Date{

private:

int day;

int month;

int year;

public:

Date();

Date(int month, int day, int year);

int getMonth();

int getDay();

int getYear();

void setMonth(int month);

void setDay(int day);

void setYear(int year);

string toString();

};

#endif

Date.cpp

#include "Date.h"

Date::Date(){

month = 1;

day = 1;

year = 1900;

}

Date::Date(int month, int day, int year){

this->month = month;

this->day = day;

this->year = year;

}

int Date::getMonth(){

return month;

}

int Date::getDay(){

return day;

}

int Date::getYear(){

return year;

}

void Date::setMonth(int month){

this->month = month;

}

void Date::setDay(int day){

this->day = day;

}

void Date::setYear(int year){

this->year = year;

}

string Date::toString(){

string ans = to_string(month)+"/";

ans += to_string(day)+"/";

ans += to_string(year);

return ans;

}

Kindly check the code output below.

You might be interested in
When companies charge different prices for the same product, they're using
Maksim231197 [3]

Answer: When companies charge different

prices for the same product, they're using

B.) Dynamic Pricing

Is the most accurate

Explanation: If a firm can find a way to charge every customer the price he/she values a good at, the firm can capture more profits than it could with a single price, in a given market.

7 0
1 year ago
How do you design and create video games for what console game That you want To have it in
Yakvenalex [24]

Answer

Making a video game is much less daunting than it might seem. While you likely aren’t going to go from having no experience to making the next Grand Theft Auto, it has actually never been easier to get started making games. Game development tools and resources have become increasingly accessible to the average person, even if they have no programming experience. Often these tools are also available for free.

To try to make things easier for those looking to get started making games, we’ve put together a list of 11 game engines / editors. Some are designed for a specific genre of game or to be incredibly easy for newcomers. Others are professional development tools for AAA games, but are effectively free to use for hobbyists and still offer a lot of learning tools to help those with limited programming experience get started.

There are, of course, a lot of things that go into game development — music, animation, sound, writing, texturing, modeling, etc. — however, the game engine / editor you choose is going to have the biggest effect on what kind of game you can make. If you have suggestions for other engines, software, or learning tools for the other aspects of development, post it in the comments.

7 0
2 years ago
Write the half function. A function call and the functionprototype
EastWind [94]

Answer:

C code for half()

#include<stdio.h>

void half(float *pv);

int main()

{

float value=5.0;  //value is initialized  

printf ("Value before half: %4.1f\n", value); // Prints 5.0

half(&value);  // the function call takes the address of the variable.

printf("Value after half: %4.1f\n", value); // Prints 2.5

}

void half(float *pv) //In function definition pointer pv will hold the address of variable passed.

{

*pv=*pv/2;  //pointer value is accessed through * operator.

}

  • This method is called call-by-reference method.
  • Here when we call a function, we pass the address of the variable instead of passing the value of the variable.
  • The address of “value” is passed from the “half” function within main(), then in called “half” function we store the address in float pointer ‘pv.’ Now inside the half(),  we can manipulate the value pointed by pointer ‘pv’. That will reflect in the main().
  • Inside half() we write *pv=*pv/2, which means the value of variable pointed by ‘pv’ will be the half of its value, so after returning from half function value of variable “value” inside main will be 2.5.

Output:

Output is given as image.

3 0
3 years ago
Write an algorithm to find the area of a parallelogram​
xeze [42]

Answer:

a = bh

Explanation:

a = Area
b = Base

h = Height

8 0
2 years ago
Why don't I have friends?
Papessa [141]

Answer:

maybe you do not ask for them i will be your friend.

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • The part of the computer that provides access to the internet is the-?
    15·2 answers
  • Websites that group individuals and organizations into clusters or groups based on some sort are considered to be what type of n
    11·1 answer
  • Is the following statement TRUE or FALSE?
    9·1 answer
  • Explain the developments RAM since it was created in 1968 til today.
    7·1 answer
  • Which component of a word processor displays the name of the document?
    13·1 answer
  • Read the citation example, and then use the drop-down menus to identify each part.
    8·2 answers
  • b. Write a complete program for the following situation related to setting the speed of a car to preset values before starting a
    5·1 answer
  • Global visibility is: Group of answer choices A visibility type where an object A has a semi-permanent reference to another obje
    14·1 answer
  • There are a wide variety of nonsampling errors that can occur during data collection including the first type, ________.
    7·1 answer
  • Which feature of cryptography is used to prove a user's identity and prevent an individual from fraudulently reneging on an acti
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!