Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Hello, this is for programming with c++ language . Below is our assignment. I cant get it right, my mind is overloading thanks to all

Hello, this is for programming with c++ language.
Below is our assignment. I cant get it right, my mind is overloading thanks to all my other classes, so I could really really use some help.
Please read the full assignment below. Then below that is the c++ default programs given. They are the bases of the lab.
Seriously, thank you for your help, I mean it!
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Below are the default programs for lab 2. This is client.cpp, myStruct.cpp,
names.cpp, time.cpp, and time.h
----------------------------------------------------------------------------------------------------
//client.cpp
using namespace std;
#include "time.h"
int main()
{
Time currTime(14,30,0);
currTime.Write();
return 0;
}
---------------------------------------------------------------------------------------------------
//myStruct.cpp
#include
#include
using namespace std;
const int SIZE = 100;
struct DateType
{
string month;
int day;
int year;
};
// Insert EventType definition HERE
void PrintStruct (DateType Holiday);
void AssignMonth (EventType Dates[]);
int main()
{
DateType Holiday;
PrintStruct (Holiday);
AssignMonth (Dates);
return 0;
}
void PrintStruct (DateType Holiday)
{
// pre : Holiday is intialized with three field values
// post : Function prints date of Holiday in form mm dd, yy
}
void AssignMonth (EventType Dates[])
{
// pre : none
// post : The month field of every date record in array is assigned a month
}
---------------------------------------------------------------------------------------------------
/ames.cpp
#include
#include
using namespace std;
void BreakDown (string name, string& first, string& last, string& mi);
int main()
{
string name, first, last, mi;
cout ";
getline (cin, name);
BreakDown (name, first, mi, last);
cout
cout
cout
return 0;
}
void BreakDown (string name, string& first, string& mi, string& last)
{
// pre : name is initialized with a full name
// post : first, mi, and last contain the individual components
// of that name
}
----------------------------------------------------------------------------------------------------
//time.cpp
//******************************************************************
// IMPLEMENTATION FILE (time.cpp)
// This file implements the Time member functions
//******************************************************************
#include
using namespace std;
#include "time.h"
// Private members of class:
// int hrs;
// int mins;
// int secs;
//******************************************************************
Time::Time( /* in */ int initHrs,
/* in */ int initMins,
/* in */ int initSecs )
// Constructor
// Precondition:
// 0
// && 0
// Postcondition:
// hrs == initHrs && mins == initMins && secs == initSecs
{
hrs = initHrs;
mins = initMins;
secs = initSecs;
}
//******************************************************************
Time::Time()
// Default constructor
// Postcondition:
// hrs == 0 && mins == 0 && secs == 0
{
hrs = 0;
mins = 0;
secs = 0;
}
//******************************************************************
void Time::Set( /* in */ int hours,
/* in */ int minutes,
/* in */ int seconds )
// Precondition:
// 0
// && 0
// Postcondition:
// hrs == hours && mins == minutes && secs == seconds
{
hrs = hours;
mins = minutes;
secs = seconds;
}
//******************************************************************
void Time::Increment()
// Postcondition:
// Time has been advanced by one second, with
// 23:59:59 wrapping around to 0:0:0
{
secs++;
if (secs > 59)
{
secs = 0;
mins++;
if (mins > 59)
{
mins = 0;
hrs++;
if (hrs > 23)
hrs = 0;
}
}
}
//******************************************************************
void Time::Write() const
// Postcondition:
// Time has been output in the form HH:MM:SS
{
if (hrs
cout
cout
if (mins
cout
cout
if (secs
cout
cout
}
//******************************************************************
bool Time::Equal( /* in */ Time otherTime ) const
// Postcondition:
// Function value == TRUE, if this time equals otherTime
// == FALSE, otherwise
{
return (hrs == otherTime.hrs && mins == otherTime.mins &&
secs == otherTime.secs);
}
//******************************************************************
bool Time::LessThan( /* in */ Time otherTime ) const
// Precondition:
// This time and otherTime represent times in the
// same day
// Postcondition:
// Function value == TRUE, if this time is earlier
// in the day than otherTime
// == FALSE, otherwise
{
return (hrs
hrs == otherTime.hrs && mins
hrs == otherTime.hrs && mins == otherTime.mins
&& secs
}
---------------------------------------------------------------------------------------------------
//time.h
//******************************************************************
// SPECIFICATION FILE (time.h)
//
// This file gives the specification
// of a Time abstract data type
//******************************************************************
class Time
{
public:
void Set( /* in */ int hours,
/* in */ int minutes,
/* in */ int seconds );
// Precondition:
// 0
// && 0
// Postcondition:
// Time is set according to the incoming parameters
void Increment();
// Postcondition:
// Time has been advanced by one second, with
// 23:59:59 wrapping around to 0:0:0
void Write() const;
// Postcondition:
// Time has been output in the form HH:MM:SS
bool Equal( /* in */ Time otherTime ) const;
// Postcondition:
// Function value == TRUE, if this time equals otherTime
// == FALSE, otherwise
bool LessThan( /* in */ Time otherTime ) const;
// Precondition:
// This time and otherTime represent times in the
// same day
// Postcondition:
// Function value == TRUE, if this time is earlier
// in the day than otherTime
// == FALSE, otherwise
Time( /* in */ int initHrs,
/* in */ int initMins,
/* in */ int initSecs );
// Precondition:
// 0
// && 0
// Postcondition:
// Class object is constructed
// && Time is set according to the incoming parameters
Time();
// Postcondition:
// Class object is constructed && Time is 0:0:0
private:
int hrs;
int mins;
int secs;
};
--------------------------------------------------------------------------------------------------
Structs, String Objects, & Classes in C++ Due Date: Wednesday, January 23rd, 1:00 PM 30 points Lab Setup 1. Make a Lab2 directory and change into it from within your CSC245 subdirectory. 2. Copy over your lab files from our class directory by typing: cp /pub/digh/CSC245/Lab2/* Notice that after that asterisk there is a space followed by a period, and then your return key.) Structs 1. Edit the file myStruct.cpp. Below the DateType struct declaration include a struct of type EventType with the following two fields: (a) A place field of type string (b) A date field of type DateType 2. Within your main function, declare a variable Holiday of type DateType. Assign "January" to the Month field, 5 to the Day field, and 2019 to the Year field. You may use one initial assignment upon declaration or you may use three separate assignment statements using the dot operator to assign your values field by field 3. Declare an array named Dates to hold 100 structs of type EventType. That is, a total of 100 hierarchical records. Use the SIZE constant already declared a variable of type DateType. The output of this function should be in the following format January 5, 2019 4. Complete the void function named PrintStruct which prints out each of the three fields of 5. Complete the void function named AssignMonth which assigns the string "January" to the Month field embedded within each of the records found within the 100 array slots of array Dates. There will be no output from this function String Objects Edit the file names.cpp. We want to write a function that, given a string representing someone's name in the form Last, First MI. breaks that string down into three substrings representing their first name, middle initial, and last name. Each of these substrings is sent back to the calling function. For example, if our input string is "Adans, John Q.", we want to return the strings "John", Q" and "Adams" So, in effect we have a "smart" function here which appears to know exactly what the components which make up a name are. The key to doing this is that every string wll be entered in the format above. That is, the last name will always be followed by a comma and a space, the first name, a space, the middle initial, and finally a period. You will need to mae use of the length, find, and substr operations. This function should not be long (like maybe around fivelins) Be sure and look up how substr differs from the Java version. Here are some helpful hints: . The middle initial will always appear one notch back from the position of the period in the . The last name will always start at position 0, and its length will always be equal to the index .The first name will always start two notches from where the comma appears. Using the string. It will of course always be of length 1 of where the comma is found. length of the string and the position of the comma, you can come up with an expression representing its length. Compile and test your program using your own name. Classes 1. Compile, but do not link, the Tine class by typing cc time.cpP This should create a time.o object file. Do an 1s to see. Remember that when you decide to utilize the Time class in a client file, you'l link with it by typing c+ client.cpp time.o 2. Create a client program in your directory named testTime.cpp. Brng in the Time class using appropriate include statement for "tine.h" Never include "time.cpp" in the client file. Declare an object variable nyTise of the class Time, initializ structor, and print it out by entering to 9:30 AM using a con- Time myTine(9,30,0) myTime.Write Notice how the Write operation has a set of opening and closing parentheses after it. These parentheses are required, and indicate that this operation takes no parameters. 3. Compile, link, and execute your client program to make sure everything is running smoothly The time above should be printed to the screen. . Now, let's complete the steps we need to add an additional observer function called WriteAmPm to your Time class. An observer function is one that has the right to use or inspect the private data, but not actually change it. We normally include a const after its prototype. 5. First off, you must add a prototype for this function within the public section of the specification file time.h. It should look as follows void WriteAmPmO const; Don't worry about adding precondition and postcondition comments. 6. Listed next is the function body for WriteAmPm that should be inserted into the implemen- tation file. Notice how we include the class name Time followed by a:: for all our function bodies in the implementation file. This makes it clear to the programmer that these functions belong to the Time class. void Time: :WriteAmPm) const bool am; int tempHrs; am-(hrs

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions