Add project files.

This commit is contained in:
Cody Cook 2023-03-17 17:36:07 -07:00
parent 12976a36f6
commit fc6f36a06c
11 changed files with 718 additions and 0 deletions

5
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"files.associations": {
"iostream": "cpp"
}
}

31
Project1.sln Normal file
View file

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.33328.57
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1\Project1.vcxproj", "{E794ABF6-346A-4345-9FA7-C70972942EC2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E794ABF6-346A-4345-9FA7-C70972942EC2}.Debug|x64.ActiveCfg = Debug|x64
{E794ABF6-346A-4345-9FA7-C70972942EC2}.Debug|x64.Build.0 = Debug|x64
{E794ABF6-346A-4345-9FA7-C70972942EC2}.Debug|x86.ActiveCfg = Debug|Win32
{E794ABF6-346A-4345-9FA7-C70972942EC2}.Debug|x86.Build.0 = Debug|Win32
{E794ABF6-346A-4345-9FA7-C70972942EC2}.Release|x64.ActiveCfg = Release|x64
{E794ABF6-346A-4345-9FA7-C70972942EC2}.Release|x64.Build.0 = Release|x64
{E794ABF6-346A-4345-9FA7-C70972942EC2}.Release|x86.ActiveCfg = Release|Win32
{E794ABF6-346A-4345-9FA7-C70972942EC2}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D81BAE95-5B37-482B-B96F-23F0A27AED08}
EndGlobalSection
EndGlobal

BIN
Project1.zip Normal file

Binary file not shown.

215
Project1/Clock.h Normal file
View file

@ -0,0 +1,215 @@
/*
* Clock app for Project One
* Clock.h header file
*
* Date: 2022/03/16
* Author: Cody Cook
*/
#pragma once // only read this file once
#include "Main.h" // grab clearScreen function
#include <iostream> // use of cin, cout
#include <string> // use of string
#include <cstring> // use of string functions
using namespace std;
unsigned int hour; // the clock's hour
unsigned int minute; // the clock's minute
unsigned int second; // the clock's second
string twoDigitString(unsigned int n)
{
/// Convert an unsigned integer to a two character string equivalent.
// the result of the conversion from int to string
string value;
// when n is less than 10, add a leading zero
if (n < 10 && n >= 0)
{
value = "0" + to_string(n);
}
else if (n >= 10 && n < 60)
{
value = to_string(n);
}
else
{
value = "00";
}
// return the new string
return value;
}
string nCharString(unsigned int n, char c)
{
/// return the c character n times.
return string(n, c);
}
string formatTime24(unsigned int h, unsigned int m, unsigned int s)
{
/// return the concatenation
return twoDigitString(h) + ":" + twoDigitString(m) + ":" + twoDigitString(s);
}
string formatTime12(unsigned int h, unsigned int m, unsigned int s)
{
/// set A M to default and change to P M when it is appropriate
string ampm = "A M";
if (h >= 12)
{
h -= 12;
ampm = "P M";
}
if (h == 0)
{
h = 12;
}
/// return the concat of thes values
return twoDigitString(h) + ":" + twoDigitString(m) + ":" + twoDigitString(s) + " " + ampm;
}
void displayClocks(unsigned int h, unsigned int m, unsigned int s)
{
/// display the clocks in a table
// clear the screen
clearScreen();
// output the table, 12 hour on left, 24 hour on right.
cout << nCharString(27, '*') << nCharString(3, ' ') << nCharString(27, '*') << endl;
cout << "*" << nCharString(6, ' ') << "12-Hour Clock" << nCharString(6, ' ') << "*" << nCharString(3, ' ');
cout << "*" << nCharString(6, ' ') << "24-Hour Clock" << nCharString(6, ' ') << "*" << endl;
cout << endl;
cout << "*" << nCharString(6, ' ') << formatTime12(h, m, s) << nCharString(7, ' ') << "*" << nCharString(3, ' ');
cout << "*" << nCharString(8, ' ') << formatTime24(h, m, s) << nCharString(9, ' ') << "*" << endl;
cout << nCharString(27, '*') << nCharString(3, ' ') << nCharString(27, '*') << endl;
}
unsigned int getHour()
{
/// return the hour value
return hour;
}
void setHour(unsigned int h)
{
/// set the hour value
hour = h;
return;
}
void addOneHour()
{
/// add one hour to the clock; if the hour is 23, set it to 0
if (getHour() >= 0 && getHour() <= 22)
{
setHour(getHour() + 1);
}
else if (getHour() == 23)
{
setHour(0);
}
return;
}
unsigned int getMinute()
{
/// return the minute value
return minute;
}
void setMinute(unsigned int m)
{
/// set the minute value
minute = m;
return;
}
void addOneMinute()
{
/// add one minute to the clock; if the minute is 59, add one hour
if (getMinute() >= 0 && getMinute() <= 58)
{
setMinute(getMinute() + 1);
}
else if (getMinute() == 59)
{
setMinute(0);
addOneHour();
}
return;
}
unsigned int getSecond()
{
/// return the second value
return second;
}
void setSecond(unsigned int s)
{
/// set the second value
second = s;
return;
}
void addOneSecond()
{
/// add one second to the clock; if the second is 59, add one minute
if (getSecond() >= 0 && getSecond() <= 58)
{
setSecond(getSecond() + 1);
}
else if (getSecond() == 59)
{
setSecond(0);
addOneMinute();
}
return;
}
void setTime()
{
/// Allow the user to set the time. Required 24-hour time format.
int userHour, userMinute, userSecond = -1; // use regular integers to handle exception
bool validTime = false; // flag to determine if the time is valid
while (!validTime)
{
// ask user for the current time; then parse and configure.
cout << "Please enter the current time in 24-hour format (HH:MM:SS): ";
// set the hour and ignore the :
cin >> userHour;
cin.ignore();
// set the minutes and ignore the :
cin >> userMinute;
cin.ignore();
// set the seconds
cin >> userSecond;
cin.ignore();
// validate the input
if ((userHour >= 0 && userHour <= 23) && (userMinute >= 0 && userMinute <= 59) && (userSecond >= 0 && userSecond <= 59))
{
validTime = true;
}
else
{
clearCin();
userHour, userMinute, userSecond = -1;
cout << "Invalid time entered. Please try again." << endl;
}
}
setHour(userHour);
setMinute(userMinute);
setSecond(userSecond);
// now that time is set, clear the screen and show the clocks
clearScreen();
displayClocks(hour, minute, second);
}

31
Project1/Main.h Normal file
View file

@ -0,0 +1,31 @@
/*
* Clock app for Project One
* Main.h header file
*
* Date: 2022/03/16
* Author: Cody Cook
*/
#pragma once
#include <iostream>
using namespace std;
void clearScreen()
{
// Clear the screen
system("CLS");
}
void clearCin()
{
/* When the cin potentially contains bad data;
* like alphabeticals when looking for unsigned integers.
* Doubles as a pause function, surprisingly, if necessary.
*/
// clear the cin and also ignore the rest of the line
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}

100
Project1/Menu.h Normal file
View file

@ -0,0 +1,100 @@
/*
* Clock app for Project One
* Menu.h header file
*
* Date: 2022/03/16
* Author: Cody Cook
*/
#pragma once // only read this file once
#include "Main.h" // get clearScreen function
#include "Clock.h" // use of clock functions
#include <iostream> // use of cin, cout
#include <string> // use of string
#include <cstring> // use of string functions
string menuCommand = "Don't Exit";
;
const char *menuItems[] = {"Add One Hour", "Add One Minute", "Add One Second", "Exit Program"};
void printMenu(const char *strings[], unsigned int numStrings, unsigned char width)
{
// print width of *, followed by a new line; top of table
cout << nCharString(width, '*') << endl;
// for each of the strings
for (unsigned int i = 0; i < numStrings; i++)
{
// set this string to s
string s = strings[i];
// create a menu option
cout << "* " << i + 1 << " - " << s << nCharString(width - s.length() - 7, ' ') << "*" << endl;
// after every line, except the last line, add a * one each side of a line of spaces
if (i < numStrings - 1)
{
cout << endl;
}
}
// print width of *, followed by a new line; bottom of table
cout << nCharString(width, '*') << endl;
}
unsigned int getMenuChoice(unsigned int maxChoice)
{
// variable for user's selection in menu
unsigned int choice;
// prompt user for option
cin >> choice;
// if the user puts a bad value, make them enter it again
while (choice < 1 || choice > maxChoice)
{
cout << "Invalid choice, please try again: ";
clearCin();
cin >> choice;
}
// return the valid choice option
return choice;
}
void mainMenu()
{
// variable for user's selection in menu
unsigned int menuChoice = getMenuChoice(4);
// options 1-3 control the clock
// option 4 exits the program
switch (menuChoice)
{
case 1:
// add one hour to the clock, then show the clock
addOneHour();
displayClocks(hour, minute, second);
break;
case 2:
// add one minute to the clock, then show the clock
addOneMinute();
displayClocks(hour, minute, second);
break;
case 3:
// add one second to the clock, then show the clock
addOneSecond();
displayClocks(hour, minute, second);
break;
case 4:
// exit the program
menuCommand = "exit";
break;
default:
// if the user puts a bad value, make them enter it again
cout << "Invalid choice, please try again." << endl;
break;
}
}

100
Project1/Project1.rc Normal file
View file

@ -0,0 +1,100 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Cody Cook @ SNHU"
VALUE "FileDescription", "My Project1 Assignment: Clock simulation"
VALUE "FileVersion", "1.0.0.1"
VALUE "InternalName", "Project1.exe"
VALUE "LegalCopyright", "Copyright (C) 2023 Cody Cook"
VALUE "OriginalFilename", "Project1.exe"
VALUE "ProductName", "Project 1: Clock Simulation"
VALUE "ProductVersion", "1.0.0.1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

158
Project1/Project1.vcxproj Normal file
View file

@ -0,0 +1,158 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{e794abf6-346a-4345-9fa7-c70972942ec2}</ProjectGuid>
<RootNamespace>Project1</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Clock.h" />
<ClInclude Include="Main.h" />
<ClInclude Include="Menu.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Project1.rc">
<DeploymentContent>true</DeploymentContent>
</ResourceCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Clock.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Menu.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Main.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Project1.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

23
Project1/main.cpp Normal file
View file

@ -0,0 +1,23 @@
/*
* Clock app for Project One
* main.cpp
*
* Date: 2022/03/16
* Author: Cody Cook
*/
#include "Clock.h"
#include "Menu.h"
void main()
{
// call for initial setting of time
setTime();
// while the user hasn't exited, show the menu and give menu options
while (menuCommand != "exit")
{
printMenu(menuItems, 4, 26);
mainMenu();
}
}

14
Project1/resource.h Normal file
View file

@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Project1.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif