Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm facing a new error in my code that I'm stuck with in C++: Here is my code with 3 files. CLOCK.H CLOCK.CPP #include Clock.h

I'm facing a new error in my code that I'm stuck with in C++:image text in transcribed

Here is my code with 3 files.

CLOCK.H

image text in transcribed

CLOCK.CPP

#include "Clock.h" #include

Clock::Clock(bool format_24) { time_t seconds = time(0); localtime_s; d_hours = 0; d_secs = 0; d_mins = 0; this->format_24 = format_24; }

void Clock::addHours(int hours) { d_hours += hours; }

void Clock::addMinutes(int mins) { d_mins += mins; }

void Clock::addSeconds(int secs) { d_secs += secs; }

void Clock::resetClock() { d_hours = 0; d_secs = 0; d_mins = 0; }

void Clock::displayTime(ostream& out) { int seconds = 0, minutes = 0, hours = 0; seconds = localTime->tm_sec + d_secs; minutes += (seconds / 60); seconds = seconds % 60;

minutes += localTime->tm_min + d_mins; hours += minutes / 60; minutes = minutes % 60;

hours = (hours + localTime->tm_hour + d_hours) % 24; string timestr = ""; out 12) { out

And CLOCKDEMO.CPP

#include "Clock.h" #include

void menu() { cout

int main() { Clock clock12(false), clock24(true); int choice; bool exit = false; while (!exit) { cout > choice; switch (choice) { case 1: clock12.addHours(1); clock24.addHours(1); break; case 2: clock12.addMinutes(1); clock24.addMinutes(1); break; case 3: clock12.addSeconds(1);

I believe that localtime_s is the big issue but everywhere I look asks me to use localTime = localtime(&seconds); which did nothing but make it impossible for me to make a .exe file for the project. Any clues or tips?

C Microsoft Visual Studio Debug Console U:\Project1\Debug\Project1.exe (process 21080) exited with code -1073741819. Press any key to close this window ... Clock.cpp Clock.h x ClockDemo.cpp Project1 (Global Scope) 4 in #include #include #include #include 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 using namespace std; class Clock { private: struct tm* localTime; int d_hours; int d_mins; int d_secs; bool format_24; public: Clock(bool format_24); void addHours(int hours); void addMinutes(int mins); void addSeconds(int secs); void resetclock(); void displayTime (ostream& out); }; #endif /* CLOCK_H_ */

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

Students also viewed these Databases questions