Archives from S:\ Drive

Good to keep around methinks
This commit is contained in:
Amrit Panesar committed 2015-04-01 21:23:15 -07:00
1 parent eadaf70b9e
commit 6dd63cc439
606 files changed
+50212

No files matched your search

@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "midterm project", "midterm project\midterm project.vcxproj", "{6959F7E3-8A71-4526-A093-07AF450CF3B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6959F7E3-8A71-4526-A093-07AF450CF3B8}.Debug|Win32.ActiveCfg = Debug|Win32
{6959F7E3-8A71-4526-A093-07AF450CF3B8}.Debug|Win32.Build.0 = Debug|Win32
{6959F7E3-8A71-4526-A093-07AF450CF3B8}.Release|Win32.ActiveCfg = Release|Win32
{6959F7E3-8A71-4526-A093-07AF450CF3B8}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,260 @@
/***************************************************************
* Project: COM 203 Midterm
* Author: Amrit Panesar
* Date: 09/04/2014
**************************************************************/
/*****************************************************************
Account Class (A bank account class with methods to deposit, withdraw, and check the balance.) (5 points)
1. Class contains 3 private data members called accountBalance, accountName and accountNum.
Choose appropriate data types for these variables
2. Write an overloaded constructor that takes one parameter of the type string.
The constructor initializes the accountName with the parameter specified.
The member variables accountBalance and accountNum are assigned some random value (No need to use rand function).
3. Write appropriate destructor, set, get and display functions.
4. The class will also contain member functions named menu, withdraw, and deposit
The withdraw function checks to see if balance is sufficient for withdrawal.
If so, decrements balance by amount; if not, prints an appropriate message indicating insufficient funds and displays the current balance.
The deposit function adds deposit amount to balance and displays new balance
The menu function will contain the following menu options: 1. Check Balance, 2. Deposit Amount, 3. Withdraw Amount, 4. Exit.
Use appropriate messages for each option selected and then call the correct function to perform the task.
*****************************************************************/
#include "includes.h"
#include "account.h"
#include "main.h"
account::account(string input) // constructor
{
setaccountName(input); // use the setter to set the input
//use rand function
setaccountBalance(10000 + rand () % 90000); // use a random total for the account balance
setaccountNum(1000000 + rand () % 9000000); // use a random number for the account number
}
account::~account()
{
cout << "destructor called" << endl;
//delete &accountNum;
//delete &accountName;
//delete &accountBalance;
}
void account::setaccountNum(int input) // setter
{
accountNum = input;
}
int account::getaccountNum() // getter
{
return accountNum;
}
string account::getPaddedAccountNum() //utility function
{
//use the space pad function defined in global scope
//to return a nicely formatted account number
return spacePad(getaccountNum());
}
void account::setaccountName(string input) // setter
{
accountName = input;
}
string account::getaccountName() // getter
{
return accountName;
}
void account::setaccountBalance(float input) // setter
{
accountBalance = input;
}
float account::getaccountBalance() // getter
{
return accountBalance;
}
void account::menu() // utility function
{
// main function that gets called after object initialization
// loop does not end until option 4 is entered.
bool cont = true;
while (cont)
{
cls();
cout << "Welcome, " << getaccountName() << ". Account Number: " << getaccountNum() << ". Balance: $" << getaccountBalance() << endl << endl;
cout << string(80,'*');
cout << "| Main Menu |";
cout << string(80,'*');
cout << "| 1. Check account balance |";
cout << "| 2. Deposit amount |";
cout << "| 3. Withdraw amount |";
cout << "| 4. Exit |";
cout << string(80,'*');
cout << "Please make a selection" << endl << ":";
char input = 0;
while (input == 0)
{
input = _getch();
cout << input;
switch (input)
{
case '1':
doAccountBalance();
break;
case '2':
doDeposit();
break;
case '3':
doWithdraw();
break;
case '4':
cont = false;
break;
default:
input = 0;
}
}
}
}
void account:: balanceform() // utility function
{
// nicely formats account number and current balance
// is called by all menu options, except quit
cout << endl << endl << endl << endl;
cout << string(8,' ') << "+-----------------------------------------+" << endl;
cout << string(8,' ') << "| Account: " << getPaddedAccountNum() << " |" << endl;
cout << string(8,' ') << "| Current balance: $" << spacePad(getaccountBalance(), 10) << " |" << endl;
cout << string(8,' ') << "+-----------------------------------------+" << endl;
cout << endl << endl << endl << endl << endl;
}
void account::doAccountBalance() // utility function, menu option 1
{
// simply displays the account number and balance using balanceform()
cls();
cout << "Welcome, " << getaccountName() << ". Account Number: " << getaccountNum() << ". Balance: $" << getaccountBalance() << endl << endl;
cout << "Viewing: Account balance" << endl;
balanceform();
pause();
}
void account::doWithdraw() // utility function, menu option 2
{
// perform a withdrawal
cls();
cout << "Welcome, " << getaccountName() << ". Account Number: " << getaccountNum() << ". Balance: $" << getaccountBalance() << endl << endl;
cout << "Withdrawal slip" << endl;
balanceform();
bool valid = false;
char perform = 0;
while (!valid)
{
// ask the user how much they wish to withdraw
cout << "How much would you like to withdraw today?" << endl << ":$";
float input;
cin >> input;
if (input > getaccountBalance()) // check condition, do we have enough money to make the withdrawal?
{
// not enough
cout << "$" << input << " is more than you have in your account.";
cout << "Please enter a different amount." << endl << endl;
}
else
{
// good amount
cout << "About to withdraw $" << input << " from account number: " << getaccountNum() << endl;
cout << "Continue? [y/N]" << endl << ":";
while (perform == 0)
{
perform = _getch();
cout << perform;
switch(toupper(perform))
{
case 'Y':
case 'N':
case CR:
case ESC:
valid = true;
break;
default:
perform = 0;
break;
}
}
cout << endl << endl;
if (toupper(perform) == 'Y')
{
// make it so
float balance = getaccountBalance();
balance -= input;
setaccountBalance(balance);
cout << "Withdrew $" << input << " from account number: " << getaccountNum() << endl;
cout << "New balance: $" << getaccountBalance() << endl << endl;
}
else
{
cout << "Aborted." << endl;
}
}
}
cout << endl << endl;
pause();
}
void account::doDeposit() // utility function, menu option 3
{
cls();
cout << "Welcome, " << getaccountName() << ". Account Number: " << getaccountNum() << ". Balance: $" << getaccountBalance() << endl << endl;
cout << "Deposit slip" << endl;
balanceform();
bool valid = false;
char perform = 0;
while (!valid)
{
// ask the user how much they wish to deposit
cout << "How much would you like to deposit today?" << endl << ":$";
float input;
cin >> input;
cout << "About to deposit $" << input << " into account number: " << getaccountNum() << endl;
cout << "Continue? [y/N]" << endl << ":";
while (perform == 0)
{
perform = _getch();
cout << perform << endl;
switch(toupper(perform))
{
case 'Y':
case 'N':
case CR:
case ESC:
valid = true;
break;
default:
perform = 0;
break;
}
}
cout << endl << endl;
if (toupper(perform) == 'Y')
{
// make it so
float balance = getaccountBalance();
balance += input;
setaccountBalance(balance);
cout << "Deposited $" << input << " into account number: " << getaccountNum() << endl;
cout << "New balance: $" << getaccountBalance() << endl << endl;
}
else
{
cout << "Aborted." << endl;
}
}
pause();
}
// hope you've enjoyed the show!
@@ -0,0 +1,58 @@
/***************************************************************
* Project: COM 203 Midterm
* Author: Amrit Panesar
* Date: 09/04/2014
**************************************************************/
/*****************************************************************
Account Class (A bank account class with methods to deposit, withdraw, and check the balance.) (5 points)
1. Class contains 3 private data members called accountBalance, accountName and accountNum.
Choose appropriate data types for these variables
2. Write an overloaded constructor that takes one parameter of the type string.
The constructor initializes the accountName with the parameter specified.
The member variables accountBalance and accountNum are assigned some random value (No need to use rand function).
3. Write appropriate destructor, set, get and display functions.
4. The class will also contain member functions named menu, withdraw, and deposit
The withdraw function checks to see if balance is sufficient for withdrawal.
If so, decrements balance by amount; if not, prints an appropriate message indicating insufficient funds and displays the current balance.
The deposit function adds deposit amount to balance and displays new balance
The menu function will contain the following menu options: 1. Check Balance, 2. Deposit Amount, 3. Withdraw Amount, 4. Exit.
Use appropriate messages for each option selected and then call the correct function to perform the task.
*****************************************************************/
#pragma once
#include "includes.h"
class account
{
private:
int accountNum;
string accountName;
float accountBalance;
void setaccountNum(int input);
int getaccountNum();
string getPaddedAccountNum();
void setaccountName(string input);
string getaccountName();
void setaccountBalance(float input);
float getaccountBalance();
void doAccountBalance();
void doDeposit();
void doWithdraw();
void balanceform();
public:
account(string name);
~account();
void menu();
};
Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

@@ -0,0 +1,33 @@
/***************************************************************
* Project: COM 203 Midterm
* Author: Amrit Panesar
* Date: 09/04/2014
**************************************************************/
#pragma once
// brilliant, right?
// hope you've been enjoyin this so far
#include <string>
#include <iostream>
#include <math.h>
#include <Windows.h>
#include <conio.h>
#include <time.h>
#include <assert.h>
#include <stdlib.h>
#include <iomanip>
#include <sstream>
#include <tchar.h>
#include <strsafe.h>
#include "atlbase.h"
#include "atlstr.h"
#include "comutil.h"
#define WIN32_LEAN_AND_MEAN
using namespace std;
@@ -0,0 +1,190 @@
/***************************************************************
* Project: COM 203 Midterm
* Author: Amrit Panesar
* Date: 09/04/2014
**************************************************************/
/***************************************************************
NOTE: Minimum requirement to qualify for grading:
1) Code must be properly indented, modularized and follows the best practices.
Account Class (A bank account class with methods to deposit, withdraw, and check the balance.) (5 points)
1. Class contains 3 private data members called accountBalance, accountName and accountNum.
Choose appropriate data types for these variables
2. Write an overloaded constructor that takes one parameter of the type string.
The constructor initializes the accountName with the parameter specified.
The member variables accountBalance and accountNum are assigned some random value (No need to use rand function).
3. Write appropriate destructor, set, get and display functions.
4. The class will also contain member functions named menu, withdraw, and deposit
The withdraw function checks to see if balance is sufficient for withdrawal.
If so, decrements balance by amount; if not, prints an appropriate message indicating insufficient funds and displays the current balance.
The deposit function adds deposit amount to balance and displays new balance
The menu function will contain the following menu options: 1. Check Balance, 2. Deposit Amount, 3. Withdraw Amount, 4. Exit.
Use appropriate messages for each option selected and then call the correct function to perform the task.
*****************************************************************/
#include "includes.h"
#include "account.h"
#include "main.h"
#include "resource.h"
int _tmain(int argc, _TCHAR* argv[]) // _tmain you say? yes. its windows.
{
ConsoleSetup("COM203 Midterm");
pause();
cls();
/*--------------------------------------------------- lets begin ----------------------------*/
string name = "";
bool named = false;
while (!named)
{
cout << string(80, '*') << endl;
// lets ask for the user's name
cout << "Welcome to the Bank Account program" << endl << endl;
cout << string(10, ' ') << string (15, '-') << endl;
cout << "Please enter your name" << endl << ":";
cin >> name;
cout << name << endl << endl;
if (!name.empty()) // ensure they didn't just hit enter (although cin doesn't allow for that by default)
{
cout << "Your name is: " << name << ". Is this correct?" << endl << "[Y/n]: ";
char charin = 0;
while (charin == 0) // yes, no, esc, or enter are acceptable
{
charin = _getch();
cout << charin;
if (charin != CR && charin != ESC)
{
switch (toupper(charin))
{
case 'Y':
named = true;
break;
case 'N':
named = false;
break;
default:
charin = 0;
break;
}
}
else if (charin == ESC) // special case for escape, just quit
{
return 0;
}
else // continue on
{
named = true;
}
}
}
cls();
}
randSeed(); // seeeeeeed
account a = account(name); // make a new account object
a.menu(); // start the menu
// endings
cls();
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "Thank you for using Banking program, " << name << ", please come again!" << endl;
cout << endl << endl << endl << endl << endl << endl << endl << endl;
pause();
}
/******************************* Just some fancy windows stuff below here *****************************/
void ConsoleSetup(char* input)
{
system("color 1e"); // change the background color to yellow on blue
ChangeConsoleIcon(IDI_ICON1); // change the console icon to the icon defined in resources.h
ChangeConsoleTitle(input); // change the console title
cout << string(80,'*') << "Welcome to " << input << " " << GetYear() << " Edition!" << endl << string(80,'*') << endl << endl; // display the title screen.
}
void ChangeConsoleTitle (const char* input)
{
time_t t = time(NULL); // get current timestamp
tm* timePtr = localtime(&t); // using the timezone the system is in
TCHAR szNewTitle[MAX_PATH]; // console title can only be as long as the maximum path length defined in windows
size_t newsize = strlen(input) + 1; // input plus null char
wchar_t * wcstring = new wchar_t[newsize]; // make a new pointer on the heap for storing the title
size_t convertedChars = 0; // number of characters converted to the above structure
mbstowcs_s(&convertedChars, wcstring, newsize, input, _TRUNCATE); // make it happen
StringCchPrintf(szNewTitle, MAX_PATH, TEXT("%s %d %s"), wcstring, GetYear(), TEXT("edition")); // move the texts into the TCHAR field
SetConsoleTitle(szNewTitle); // set the console title
}
void ChangeConsoleIcon (const int resource_number)
{
HMODULE hMainMod = GetModuleHandle(0);
assert (hMainMod);
HICON hMainIcon = ::LoadIcon(hMainMod, MAKEINTRESOURCE(resource_number));
assert (hMainIcon);
// Load kernel 32 library
HMODULE hMod = LoadLibrary( _T( "Kernel32.dll" ));
assert (hMod);
// Load console icon changing procedure
typedef DWORD (__stdcall *SCI)(HICON);
SCI pfnSetConsoleIcon = reinterpret_cast<SCI>(GetProcAddress(hMod, "SetConsoleIcon"));
assert (pfnSetConsoleIcon);
// Call function to change icon
pfnSetConsoleIcon (hMainIcon);
FreeLibrary (hMod);
}// End ChangeIcon
int GetYear()
{
time_t t = time(NULL);
tm* timePtr = localtime(&t);
return timePtr->tm_year + 1900;
}
void pause()
{
cout << "Press any key to continue. . ." << endl;
_getch();
}
void cls()
{
system("cls");
}
void randSeed()
{
time_t t = time(NULL);
srand(t);
}
string spacePad(int input, int length, bool right)
{
ostringstream ss;
if (!right)
ss << left << setw( length ) << setfill( ' ' ) << input;
else
ss << right << setw( length ) << setfill( ' ' ) << input;
return ss.str();
}
@@ -0,0 +1,26 @@
/***************************************************************
* Project: COM 203 Midterm
* Author: Amrit Panesar
* Date: 09/04/2014
**************************************************************/
#pragma once
#include "includes.h"
// not a whole lot going on here
// just enough to be called from the account class
void ChangeConsoleTitle (const char* input);
void ChangeConsoleIcon (int resource_number);
void ConsoleSetup (char* input);
int GetYear();
void pause();
void cls();
void randSeed();
string spacePad(int input, int length = 7, bool right = false); // ah thank god for default arguments
enum { NUL = 0, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, HT,
LF, VT, FF, CR, SO, SI, DLE, DC1, DC2, DC3, DC4, NAK,
SYN, ETB, CAN, EM, SUB, ESC, FS, GS, RS, US, DEL = 127 };
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" 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>
</ItemGroup>
<ItemGroup>
<ClCompile Include="account.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="account.h" />
<ClInclude Include="includes.h" />
<ClInclude Include="main.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resource.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="icon.ico" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6959F7E3-8A71-4526-A093-07AF450CF3B8}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>midtermproject</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</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>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,49 @@
<?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;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;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>
<ClCompile Include="account.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="account.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="includes.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="Resource.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="icon.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>