Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help on C++ project I am having some difficulty with this. For this project

ID: 3866264 • Letter: N

Question

Need help on C++ project I am having some difficulty with this.

For this project you are to finish programming an application that opens a Console window, asks for some information and displays the time, day of the week, and the date. The application updates the time every second and also displays it in various colors. It will be your responsibility to complete the “CTimeClass” that is partially implemented/defined in “TimeClass.h” and “TimeClass.cpp

Since the beginning of this class we have been putting all of our code into one file. In the real world this is not the case. Just as we break up our program and place code in functions, we can also do a better job at organization by putting code in separate files. As long as the compiler and linker know of them, the end result is exactly the same. “.h” files (header) typically contain declarations. In this programming exercise they will contain the class declarations. The “.cpp” (implementation) files contain definitions.

For this project you will download the zipped file that contains a VS2017 solution that contains all of the files that you will need. Please make sure that you extract or copy the files to another directory and not just double click on the solutions file (.sln) inside the zip file. If you do VS2017 will complain that the project was not loaded correctly.

Again it is your job to complete the program implementation and flesh out CTimeClass.

The Code

CConsoleClass” is a class that encapsulates some of the functionality of the console window. You do not have to change anything in this class. Just create an instance of it and call it’s methods/functions. See the header and implementation files for comments.

CTimeClass” is a class that encapsulates the functionality dates and time. “TimeClass.h” is complete. You only need to implement the following functions in the file “TimeClass.cpp”:

short GetYear();

string GetMonth();

short GetDay();

string GetDayOfWeek();

short GetHour();

short GetMinute();

short GetSecond();

The constructor is finished and needs no modification.

ConsoleWindowClock.cpp” is where “main” lives. This is where you will be doing most of your programming. Take a look at the example executable for a working example. You will notice that the example pauses for about one second before updating. Use the function “Sleep(1000);” to put the console window to sleep for 1 second. Use “system(“cls”);” to clear the console window when you need to display fresh information. Example input should look like the following:

The output should then appear and resemble the following:

When complete there are 2 files to submit, ConsoleWindowClock.cpp which will contain the function main that implements your program and the file TimeClass.cpp which is the implementation of the functions declared in TimeClass.h.

TimeClass.cpp

#include "TimeClass.h"
///////////////////////////////////////////////////////////////////////////////
// Class to help with the usage of time.
///////////////////////////////////////////////////////////////////////////////
CTimeClass::CTimeClass()
{
   // Notice that the time is stored whenever this time object is created.
   // Use this to your advantage in "main".

   // "m_st" holds the time and date information.
   GetLocalTime(&m_st);
}
///////////////////////////////////////////////////////////////////////////////
CTimeClass::~CTimeClass()
{
   // Empty - Nothing to destroy here.
}
short CTimeClass::GetYear()
{
   // Place your code here to return the year as a short.
}
///////////////////////////////////////////////////////////////////////////////
string CTimeClass::GetMonth()
{
   // Place your code here to return the month as a string.
}
///////////////////////////////////////////////////////////////////////////////
short CTimeClass::GetDay()
{
   // Place your code here to return the day as a short.
}
///////////////////////////////////////////////////////////////////////////////
string CTimeClass::GetDayOfWeek()
{
   // Place your code here to return the day of the week as a string.
}
///////////////////////////////////////////////////////////////////////////////
short CTimeClass::GetHour()
{
   // Place your code here to return the hour as a short.
}
///////////////////////////////////////////////////////////////////////////////
short CTimeClass::GetMinute()
{
   // Place your code here to return the minute as a short.
}
///////////////////////////////////////////////////////////////////////////////
short CTimeClass::GetSecond()
{
   // Place your code here to return the second as a short.
}

ConsoleWindowClock.cpp

// ConsoleWindowClock.cpp : Defines the entry point for the console application.
//
#include "ConsoleClass.h"
#include "TimeClass.h"
#include <iostream>
#include <iomanip>
using namespace std;
///////////////////////////////////////////////////////////////////////////////////
int main()
{
  
   // Instantiate "CConsoleClass" and call its functions here to impliment the programming assignment.
   // Instantiate "CTimeClass" and call its functions here to impliment the programming assignment.

   return 0;
}

ConsoleClass.cpp

include "ConsoleClass.h"
#include <bitset>
#include <time.h>
///////////////////////////////////////////////////////////////////////////////
// Helper Class to encapsulates some of the functionality of the Windows Console.
///////////////////////////////////////////////////////////////////////////////
CConsoleClass::CConsoleClass()
{
   // Get a handle to the console. Used in a bunch of
   // other Windows function calls later on.
   m_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
   if (m_hConsole == NULL)
       exit(1);

   // Hide the console cursor...
   CONSOLE_CURSOR_INFO ConCurInf;
   ConCurInf.dwSize = 10;
   ConCurInf.bVisible = FALSE;
   SetConsoleCursorInfo(m_hConsole, &ConCurInf);

   // Initialize the console window size.
   SetConsoleWindowSize(70, 20);

   // Seed the random-number generator with the current time so that
   // the numbers will be different every time we run.
   srand(static_cast<unsigned>(time(NULL)));

}
///////////////////////////////////////////////////////////////////////////////
CConsoleClass::~CConsoleClass()
{
   // Empty - Nothing to destroy here.
}
///////////////////////////////////////////////////////////////////////////////
// See: http://www.cplusplus.com/forum/windows/10731/
///////////////////////////////////////////////////////////////////////////////
bool CConsoleClass::SetConsoleWindowSize(int iWidth, int iHeight)
{
   // Call the Windows function to get the console window buffer...
   CONSOLE_SCREEN_BUFFER_INFO csbi;
   if (!GetConsoleScreenBufferInfo(m_hConsole, &csbi))
       return false;

   // Set the window size...
   SMALL_RECT r;
   r.Left = r.Top = 0;
   r.Right = iWidth - 1;
   r.Bottom = iHeight - 1;
   SetConsoleWindowInfo(m_hConsole, TRUE, &r);

   // Set the window buffer size...
   COORD c;
   c.X = iWidth;
   c.Y = iHeight;
   SetConsoleScreenBufferSize(m_hConsole, c);

   // Save these for later use.
   m_iConsoleWidth = iWidth;
   m_iConsoleHeight = iHeight;

   return true;
}
///////////////////////////////////////////////////////////////////
// Set the Console window text and background colors...
void CConsoleClass::SetConsoleColor(CONSOLECOLOR eColorText, CONSOLECOLOR eColorBkGrnd)
{
   COORD coord = { 0, 0 };
   DWORD dwWritten;

   // These should have beed set earlier.
   // We need to fill the entire console window with the choosen color.
   int iNumCharsToFill = m_iConsoleWidth * m_iConsoleHeight;

   // Determiene the text color...
   // FOREGROUND_RED, FOREGROUND_GREEN, and FOREGROUND_BLUE are Microsoft defined bitmaps.
   int iTextColor = 0;
   switch (eColorText)
   {
   case RED:
       iTextColor = FOREGROUND_RED;
       break;
   case GREEN:
       iTextColor = FOREGROUND_GREEN;
       break;
   case BLUE:
       iTextColor = FOREGROUND_BLUE;
       break;
   default:
       iTextColor = GetRandomTextColor();
       break;
   }

   // Determiene the text color...
   // BACKGROUND_RED, BACKGROUND_GREEN, and BACKGROUND_BLUE are Microsoft defined bitmaps.
   int iBkGrndColor = 0;
   switch (eColorBkGrnd)
   {
   case RED:
       iBkGrndColor = BACKGROUND_RED;
       break;
   case GREEN:
       iBkGrndColor = BACKGROUND_GREEN;
       break;
   case BLUE:
       iBkGrndColor = BACKGROUND_BLUE;
       break;
   default:
       iBkGrndColor = GetRandomBackGrndColor();
       break;
   }

   // Are text color and background color the same? We don't want that (can't see the text)
   // some bitmap manipulation....
   while (iTextColor == (iBkGrndColor >> 4))
   {
       // Then change it....
       if (eColorText == RANDOM)
           iTextColor = GetRandomTextColor();
       else
           iBkGrndColor = GetRandomBackGrndColor();
   }

   // Call the Windows API function to set the Console window attributes.
   FillConsoleOutputAttribute(m_hConsole, iTextColor | iBkGrndColor, iNumCharsToFill, coord, &dwWritten);
}
////////////////////////////////////////////////////
// See: http://www.cplusplus.com/forum/general/118967/
////////////////////////////////////////////////////
void CConsoleClass::SetFontSize(int FontSize)
{
   // Call the Windows API function to set the Console window attributes.
   CONSOLE_FONT_INFOEX info = { 0 };
   info.cbSize = sizeof(info);
   info.dwFontSize.Y = FontSize; // leave X as zero
   info.FontWeight = FW_NORMAL;
   lstrcpy(info.FaceName, L"Lucida Console"); // NOTE: You have other choices here
   SetCurrentConsoleFontEx(m_hConsole, NULL, &info);
}
////////////////////////////////////////////////////
int CConsoleClass::GetRandomTextColor()
{
   // Use the C++ STL to randomize the text color
   std::bitset<3> bsColorText(rand());
   return bsColorText.to_ulong();
}
////////////////////////////////////////////////////
int CConsoleClass::GetRandomBackGrndColor()
{
   // Use the C++ STL to randomize the backgronund color
   std::bitset<3> bsColorBkgnd(rand());
   return bsColorBkgnd.to_ulong() << 4;
}

ENITCS2530Demo-CompletedConsoleWindo × This is the Console Window Clock Please enter the window size in characters (width and height): 8 20 Please enter the font size: 18 Enter the Text color (e-RED, 1-GREEN, 2-BLUE, -1-random) 2 Enter the background color (e-RED, 1-GREEN, 2-BLUE, -1-random): 1 2

Explanation / Answer

TimeClass.cpp

#include "TimeClass.h"
///////////////////////////////////////////////////////////////////////////////
// Class to help with the usage of time.
///////////////////////////////////////////////////////////////////////////////
CTimeClass::CTimeClass()
{
   // Notice that the time is stored whenever this time object is created.
   // Use this to your advantage in "main".
   SYSTEMTIME m_st;
   // "m_st" holds the time and date information.
   GetLocalTime(&m_st);
   year = m_st.wYear;
   month = m_st.wMonth;
   day = m_st.wDay;
   hour = m_st.wHour;
   minute = m_st.wMinute;
   second = m_st.wSecond;
   dayOfWeek = m_st.wDayOfWeek;
}
///////////////////////////////////////////////////////////////////////////////
CTimeClass::~CTimeClass()
{
   // Empty - Nothing to destroy here.
}
short CTimeClass::GetYear()
{
   return year;
}
///////////////////////////////////////////////////////////////////////////////
string CTimeClass::GetMonth()
{
   return month;
}
///////////////////////////////////////////////////////////////////////////////
short CTimeClass::GetDay()
{
   return day;
}
///////////////////////////////////////////////////////////////////////////////
string CTimeClass::GetDayOfWeek()
{
   return dayOfWeek;
}
///////////////////////////////////////////////////////////////////////////////
short CTimeClass::GetHour()
{
   return hour
}
///////////////////////////////////////////////////////////////////////////////
short CTimeClass::GetMinute()
{
   return minute
}
///////////////////////////////////////////////////////////////////////////////
short CTimeClass::GetSecond()
{
   return second;
}

ConsoleWindowClock.cpp

// ConsoleWindowClock.cpp : Defines the entry point for the console application.
//
#include "ConsoleClass.h"
#include "TimeClass.h"
#include <iostream>
#include <iomanip>
using namespace std;
///////////////////////////////////////////////////////////////////////////////////
int main()
{

   int wid, hig, fSize, tColor, bColor;
   cout << "This is the console window clock" << endl
        << "Please enter window size in characters (width and height): ";
   cin >> wid >> hig;

   cout << "Enter the font size: ";
   cin >>fSize;

   cout << "Enter the text color (0=RED, 1=GREEN, 2=BLUE, -1=random): ";
   cin >>tColor;

   cout << "Enter the background color (0=RED, 1=GREEN, 2=BLUE, -1=random): ";
   cin >>bColor;

   // Instantiate "CConsoleClass" and call its functions here to impliment the programming assignment.
   CONSOLECOLOR bc;
   CONSOLECOLOR tc;
   if (bColor == 0)
   bc = RED;
   else if (bColor == 1)
   bc = GREEN;
   else if (bColor == 2)
   bc = BLUE;
   else if (bColor == -1)
   tc = RANDOM;
   if (tColor == 0)
   tc = RED;
   else if (tColor == 1)
   tc = GREEN;
   else if (tColor == 2)
   tc = BLUE;
   else if (tColor == -1)
   tc = RANDOM;


    CConsoleClass ccc;
    ccc.SetConsoleWindowSize(wid, hig);
    ccc.SetFontSize(fSize);
    ccc.SetConsoleColor(tc, bc);
    ccc.SetConsoleColor(tc, bc);


   CTimeClass ctc;
   short day = ctc.getDay();
   short month = ctc.getMonth();
   short year = ctc.getYear();
   short dow = ctc.getDayOfWeek();
   short hour = ctc.getHour();
   short minute = ctc.getMinute();
   short ysecond = ctc.getSecond();

   //now we have to print

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote