Question

In: Computer Science

C++ Program for Project Alarm. ------------------------------------------------------------------------------ Fix ALL Errors in my EXISTING code for ALL 5...

C++ Program for Project Alarm.

------------------------------------------------------------------------------

Fix ALL Errors in my EXISTING code for ALL 5 files.  

MUST add comments for FULL CREDIT.

Take a screenshot of the working solution output.

-------------------------------------------------------------------------------

Instructions:

Use class composition to define and implement a new class called Alarm that contains a Time member variable.

A. Define and implement the class Alarm as follows: The class Alarm consists of two private member variables:

description of type string and atime of type Time. The class Alarm also includes the following public

member functions:

- print to print out the alarm’s description and hour, minute, and second of the alarm time.

- setDescription to accept a string argument and use it to set the description member variable.

-setAtime to accept three integers (for hour, minute, and second) to set the atime member variable

(alarm time).

- getDescription to return the value of the description member variable.

- getAtime to return the atime member as a Time object.

- A default constructor that initializes the description to the string “None” and the alarm time to

00:00:00.

- An overloaded constructor that accepts a string argument for the alarm description and three int arguments

(as the hour, minute, and second) and use them to initialize the description and atime member

variables of an Alarm object.

- An overloaded constructor that accepts a string argument for the alarm description and a Time object and

use them to initialize the description and atime member variables of an Alarm object.

- An equals function to compare two Alarm objects’ values. Return true if both objects have the same

values of the member variables. Otherwise, return false.

B. In the function main, write statements to declare Alarm class objects and test your class implementation.

Hint: (Time.h, Time.cpp, Alarm.h, Alarm.cpp, Main.cpp.)

-------------------------------------------------------------------------------------

Note:(Detailed comments are helpful for me so I can better

understand where I went wrong. So please be detailed.

Edit my code so it works, but do not add highly advanced code.)

------------------------------------------------------------------------------------

MY CODE:

-------------------------------------------------------------------------------------

//////////////////////////////////// Time.h ///////////////////////////////////////////

#include<iostream>
using namespace std;

class Time
{

private:

   int hour;
   int minute;
   int second;


public:
   /* Constructors */
   Time(); //Default constructor
   Time(int h, int m, int s); //Overloaed Constructor
   Time(const Time&);


   /* Functions */
   void print(); // Print the Time
   int getHour(); //Accessor function
   int getMinute(); //Accessor function
   int getSecond(); //Accessor function

   void setHour(int h); //Mutator change Hour
   void setMinute(int m); //Mutator Change Minute
   void setSecond(int s); //Mutator Change Second
   void setTime(int h, int m, int s); //Overloaded Constructor
   bool equals(const Time&)const;
};

////////////////////////////////END OF Time.h/////////////////////////////////////

//////////////////////////////////// Time.cpp ////////////////////////////////////////

#include "Time.h"
#include "Alarm.h"
#include<iomanip>

using namespace std;

void Time::print()
{
cout << setw(2) << setfill('0') << hour << ":"
<< setw(2) << setfill('0') << minute << ":"
<< setw(2) << setfill('0') << second << endl;
}


// Default Constructor
Time::Time()
{
hour = 0; minute = 0; second = 0;
}

// copy Constructor
Time::Time(const Time& other) {
hour = other.hour;
minute = other.minute;
second = other.second;
}

// Accessor for Hour
int Time::getHour()
{
return hour;
}

// Accessor for Minute
int Time::getMinute()
{
return minute;
}

// Accessor for Second
int Time::getSecond()
{
return second;
}

// Mutator for Hour
void Time::setHour(int h)
{
// Validate Hour value
if (h >= 0 && h <= 23)
hour = h;
else
hour = 0;
}


// Mutator for Minute
void Time::setMinute(int m)
{
// Validate Minute value
if (m >= 0 && m <= 59)
minute = m;
else
minute = 0;
}


// Mutator for Second
void Time::setSecond(int s)
{
if (s >= 0 && s <= 59)
second = s;
else
second = 0;
}

// Set Time function
void Time::setTime(int h, int m, int s)
{
setHour(h);
setMinute(m);
setSecond(s);
}

Time::Time(int h, int m, int s)
{
setTime(h, m, s);
}

bool Time::equals(const Time& other)const
{

return hour == other.hour && minute == other.minute && second == other.second;
}

////////////////////////////////END OF Time.cpp/////////////////////////////////

//////////////////////////////////// Alarm.h //////////////////////////////////////////

#include<iostream>
using namespace std;

class Alarm
{
private:

   string description;
   Time atime;

public:
   /* Constructors */
   void print();
   void setDescription(string i);
   void setAtime(int h, int m, int s);

   Time getAtime();
   void getDescription(); // Accessor Function
  


   Alarm() {description = "None";}

   Alarm(string i, int h, int m, int s);

};

//////////////////////////////// END OF Alarm.h /////////////////////////////////

/////////////////////////////////// Alarm.cpp //////////////////////////////////////

#include "Time.h"
#include "Alarm.h"
#include<iomanip>
using namespace std;


void Alarm::print()
{
   cout << description << "";
atime.print();
}

void Alarm::setDescription(string i)
{
   description = i;
}

void Alarm::setAtime(int h, int m, int s)
{
   atime.setTime(h, m, s);
}


Time Alarm::getAtime()
{
   return atime;
}

void Alarm::getDescription()
{
}

Alarm::Alarm()
{
   description = "None";
}

Alarm::Alarm(string desc, int hour, int minute, int second) : atime(hour, minute, second)
{
   description = desc;
}

bool Alarm::equals(const Alarm& other)
{
   return atime.equals(other.atime) && description == other.description;
}

//////////////////////////////// END OF Alarm.cpp ////////////////////////////

//////////////////////////////////// Main.cpp /////////////////////////////////////////

// I didn't write the main.

// complete the main.

/////////////////////////////////// END OF Main.cpp ////////////////////////

------------------------------------------------------------------------------------------------------------

Thank you.

Solutions

Expert Solution

#include<iostream>
using namespace std;

class Time
{

private:

   int hour;
   int minute;
   int second;

public:
   /* Constructors */
   Time(); //Default constructor
   Time(int h, int m, int s); //Overloaed Constructor
   Time(const Time&);


   /* Functions */
   void print(); // Print the Time
   int getHour(); //Accessor function
   int getMinute(); //Accessor function
   int getSecond(); //Accessor function

   void setHour(int h); //Mutator change Hour
   void setMinute(int m); //Mutator Change Minute
   void setSecond(int s); //Mutator Change Second
   void setTime(int h, int m, int s); //Overloaded Constructor
   bool equals(const Time&)const;
}

#include "Time.h"
#include "Alarm.h"
#include<iomanip>

using namespace std;

void Time::print()
{
cout << setw(2) << setfill('0') << hour << ":"
<< setw(2) << setfill('0') << minute << ":"
<< setw(2) << setfill('0') << second << endl;
}


// Default Constructor
Time::Time()
{
hour = 0; minute = 0; second = 0;
}

// copy Constructor
Time::Time(const Time& other) {
hour = other.hour;
minute = other.minute;
second = other.second;
}

// Accessor for Hour
int Time::getHour()
{
return hour;
}

// Accessor for Minute
int Time::getMinute()
{
return minute;
}

// Accessor for Second
int Time::getSecond()
{
return second;
}

// Mutator for Hour
void Time::setHour(int h)
{
// Validate Hour value
if (h >= 0 && h <= 23)
hour = h;
else
hour = 0;
}


// Mutator for Minute
void Time::setMinute(int m)
{
// Validate Minute value
if (m >= 0 && m <= 59)
minute = m;
else
minute = 0;
}


// Mutator for Second
void Time::setSecond(int s)
{
if (s >= 0 && s <= 59)
second = s;
else
second = 0;
}

// Set Time function
void Time::setTime(int h, int m, int s)
{
setHour(h);
setMinute(m);
setSecond(s);
}

Time::Time(int h, int m, int s)
{
setTime(h, m, s);
}

bool Time::equals(const Time& other)const
{

return hour == other.hour && minute == other.minute && second == other.second;
}

#include<iostream>
using namespace std;

class Alarm
{
private:

   string description;
   Time atime;

public:
   /* Constructors */
   void print();
   void setDescription(string i);
   void setAtime(int h, int m, int s);

   Time getAtime();
   void getDescription(); // Accessor Function
  


   Alarm() {description = "None";}

   Alarm(string i, int h, int m, int s);

};

#include "Time.h"
#include "Alarm.h"
#include<iomanip>
using namespace std;


void Alarm::print()
{
   cout << description << "";
atime.print();
}

void Alarm::setDescription(string i)
{
   description = i;
}

void Alarm::setAtime(int h, int m, int s)
{
   atime.setTime(h, m, s);
}


Time Alarm::getAtime()
{
   return atime;
}

void Alarm::getDescription()
{
}

Alarm::Alarm()
{
   description = "None";
}

Alarm::Alarm(string desc, int hour, int minute, int second) : atime(hour, minute, second)
{
   description = desc;
}

bool Alarm::equals(const Alarm& other)
{
   return atime.equals(other.atime) && description == other.description;
}


Related Solutions

q7.4 Fix the errors in the code (in C) //This program is supposed to scan 5...
q7.4 Fix the errors in the code (in C) //This program is supposed to scan 5 ints from the user //Using those 5 ints, it should construct a linked list of 5 elements //Then it prints the elements of the list using the PrintList function #include <stdio.h> struct Node{ int data; Node* next; }; int main(void){ struct Node first = {0, 0}; struct Node* second = {0, 0}; Node third = {0, 0}; struct Node fourth = {0, 0}; struct...
q7.1 Fix the errors in the code (in C) //This program should read a string from...
q7.1 Fix the errors in the code (in C) //This program should read a string from the user and print it using a character pointer //The program is setup to use pointer offset notation to get each character of the string #include <stdio.h> #include <string.h> int main(void){ char s[1]; scanf(" %c", s); char *cPtr = s[1]; int i=0; while(1){ printf("%c", cPtr+i); i++; } printf("\n"); }
Please fix all the errors in this Python program. import math def solve(a, b, c): """...
Please fix all the errors in this Python program. import math def solve(a, b, c): """ Calculate solution to quadratic equation and return @param coefficients a,b,class @return either 2 roots, 1 root, or None """ #@TODO - Fix this code to handle special cases d = b ** 2 - 4 * a * c disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) return root1, root2 if...
Please fix all of the errors in this Python Code. import math """ A collection of...
Please fix all of the errors in this Python Code. import math """ A collection of methods for dealing with triangles specified by the length of three sides (a, b, c) If the sides cannot form a triangle,then return None for the value """ ## @TODO - add the errlog method and use wolf fencing to identify the errors in this code def validate_triangle(sides): """ This method should return True if and only if the sides form a valid triangle...
C++ : Find the syntax errors in the following program. For each syntax error, fix it...
C++ : Find the syntax errors in the following program. For each syntax error, fix it and add a comment at the end of the line explaining what the error was. #include <iostream> #include <cmath> using namespace std; int main(){ Double a, b, c; 2=b; cout<<"Enter length of hypotenuse"<<endl; cin>>c>>endl; cout>>"Enter length of a side"<<endl; cin>>a; double intermediate = pow(c, 2)-pow(a, 2); b = sqrt(intermediate); cout<<"Length of other side is:" b<<endline; return 0; }
Can you fix my code and remove the errors? Thank you!! ^^ ////////////////////////////////////////////////////////////////////////////////////////////////////// public class StackException<T,...
Can you fix my code and remove the errors? Thank you!! ^^ ////////////////////////////////////////////////////////////////////////////////////////////////////// public class StackException<T, size> extends Throwable { private final T[] S = null ; public StackException(String s) { } public T top() throws StackException { if (isEmpty()) throw new StackException("Stack is empty."); int top = 0; return S[top]; } private boolean isEmpty() { return false; } public T pop() throws StackException { T item; if (isEmpty()) throw new StackException("Stack underflow."); int top = 0; item = S[top];...
Can you fix my code and remove the errors in java language. public class LinkedStack<T> implements...
Can you fix my code and remove the errors in java language. public class LinkedStack<T> implements Stack<T> { private Node<T> top; private int numElements = 0; public int size() { return (numElements); } public boolean isEmpty() { return (top == null); } public T top() throws StackException { if (isEmpty()) throw new StackException("Stack is empty."); return top.info; } public T pop() throws StackException { Node<T> temp; if (isEmpty()) throw new StackException("Stack underflow."); temp = top; top = top.getLink(); return temp.getInfo();...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
Python programming: can someone please fix my code to get it to work correctly? The program...
Python programming: can someone please fix my code to get it to work correctly? The program should print "car already started" if you try to start the car twice. And, should print "Car is already stopped" if you try to stop the car twice. Please add comments to explain why my code isn't working. Thanks! # Program goals: # To simulate a car game. Focus is to build the engine for this game. # When we run the program, it...
fix all errors in code below: PLEASE DO ASAP, THIS IS IN MATLAB %Welcome Message fprintf('****Welcome...
fix all errors in code below: PLEASE DO ASAP, THIS IS IN MATLAB %Welcome Message fprintf('****Welcome to Comida Mexicana De Mentiras****\n'); flag =0; while flag ==1 % Asking the user for the order choice = input('Please enter your order \n 1. Burrito Bowl \n 2.Burrito \n 3. Tacos \n Enter 1 or 2 or 3: ','s'); switch choice case choice==1 % For Burrito Bowl BaseCost = 4; [Protein, PC] = proteinChoice(); [FinalAmount,~]= AmountCalculator(BaseCost,PC); displayMessage("Burrito Bowl",Protein,FinalAmount); case choice==2 end end %...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT