first semester files

This commit is contained in:
Adog64 2024-02-22 14:31:08 -05:00
parent 0f26c9f73d
commit 2d4bbf49a4
242 changed files with 360411 additions and 0 deletions

View File

@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}

View File

@ -0,0 +1,7 @@
{
"files.associations": {
"ostream": "cpp",
"iostream": "cpp"
},
"C_Cpp.errorSquiggles": "Disabled"
}

View File

@ -0,0 +1,27 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

View File

@ -0,0 +1,44 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 2
* Assignment Date: 9/8/2021
* File Name: BinaryConverter.cpp
*****************************************************************
* ID: Lab 0 Problem 1
* Purpose: Convert an user-entered integer to a binary string
*****************************************************************/
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x, n, k, a, c;
// Data collection
cout << "Enter an integer in the decimal number system: ";
cin >> x;
cout << "Binary value of the number is: ";
//calculate the number of bits being used
for ( a = 1; n != 0; a++ )
{
n = n / 2;
}
a = a - 2;
// get each bit in the integer by bitshifting it one place to the left and reading the ones place for each bit in the number
for ( c = a; c >= 0; c-- )
{
k = x >> c;
if ( k & 1 )
cout << "1";
else
cout << "0";
}
return 0;
}

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wxBase", "wxBase\wxBase.vcxproj", "{128B02C4-4E1C-4F63-8A0A-B32DD6B4A54B}"
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
{128B02C4-4E1C-4F63-8A0A-B32DD6B4A54B}.Debug|x64.ActiveCfg = Debug|x64
{128B02C4-4E1C-4F63-8A0A-B32DD6B4A54B}.Debug|x64.Build.0 = Debug|x64
{128B02C4-4E1C-4F63-8A0A-B32DD6B4A54B}.Debug|x86.ActiveCfg = Debug|Win32
{128B02C4-4E1C-4F63-8A0A-B32DD6B4A54B}.Debug|x86.Build.0 = Debug|Win32
{128B02C4-4E1C-4F63-8A0A-B32DD6B4A54B}.Release|x64.ActiveCfg = Release|x64
{128B02C4-4E1C-4F63-8A0A-B32DD6B4A54B}.Release|x64.Build.0 = Release|x64
{128B02C4-4E1C-4F63-8A0A-B32DD6B4A54B}.Release|x86.ActiveCfg = Release|Win32
{128B02C4-4E1C-4F63-8A0A-B32DD6B4A54B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {133E650D-4238-4F51-81BB-171D8152659E}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,24 @@
/*************************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 12.13.2021
*
* File Names: cApp.h | cApp.cpp
* cMain.h | cMain.cpp
* ReservationDialog.h | ReservationDialog.cpp
* Restaurant.h | Restaurant.cpp
* README.txt |
***************************************************************************
* ID: CSNP Final Project
* Purpose: A reservation management system
* Key Features:
* - Create a walk-in reservation for a party of <N> people
* - Create a reservation for a party of <N> people at a certain time
* - See if tables are reserved or not
* - Check wait times for different party sizes
* - Edit reservations (change any component)
* - Add additional tables to the restaurant
*
* Created on top of wxWidgets cross-platform GUI framework for C++
***************************************************************************/

View File

@ -0,0 +1,64 @@
#include "ReservationDialog.h"
using namespace std;
wxBEGIN_EVENT_TABLE(ReservationDialog, wxDialog)
EVT_BUTTON(10004, Ok)
EVT_BUTTON(10005, Cancel)
wxEND_EVENT_TABLE()
ReservationDialog::ReservationDialog() : wxDialog(nullptr, wxID_ANY, "Reserve Table", wxPoint(100, 100), wxSize(260, 240))
{
lblName = new wxStaticText(this, wxID_ANY, "*Reservation Name:", wxPoint(10, 10));
lblNumber = new wxStaticText(this, wxID_ANY, "*Phone Number:", wxPoint(10, 40));
lblSize = new wxStaticText(this, wxID_ANY, "*Party Size:", wxPoint(10, 70));
lblTime = new wxStaticText(this, wxID_ANY, "Reservation Time:", wxPoint(10, 100));
lblDate = new wxStaticText(this, wxID_ANY, "Reservation Date:", wxPoint(10, 130));
txtName = new wxTextCtrl(this, wxID_ANY, "", wxPoint(120, 10));
txtNumber = new wxTextCtrl(this, wxID_ANY, "", wxPoint(120, 40));
txtSize = new wxTextCtrl(this, wxID_ANY, "", wxPoint(120, 70));
txtTime = new wxTextCtrl(this, wxID_ANY, "", wxPoint(120, 100));
txtDate = new wxTextCtrl(this, wxID_ANY, "", wxPoint(120, 130));
btnOk = new wxButton(this, 10004, "OK", wxPoint(80, 165));
btnCancel = new wxButton(this, 10005, "Cancel", wxPoint(155, 165));
}
ReservationDialog::ReservationDialog(string name, string number, string size, string time, string date) : wxDialog(nullptr, wxID_ANY, "Reserve Table", wxPoint(100, 100), wxSize(260, 240))
{
lblName = new wxStaticText(this, wxID_ANY, "*Reservation Name:", wxPoint(10, 10));
lblNumber = new wxStaticText(this, wxID_ANY, "*Phone Number:", wxPoint(10, 40));
lblSize = new wxStaticText(this, wxID_ANY, "*Party Size:", wxPoint(10, 70));
lblTime = new wxStaticText(this, wxID_ANY, "Reservation Time:", wxPoint(10, 100));
lblDate = new wxStaticText(this, wxID_ANY, "Reservation Date:", wxPoint(10, 130));
txtName = new wxTextCtrl(this, wxID_ANY, name, wxPoint(120, 10));
txtNumber = new wxTextCtrl(this, wxID_ANY, number, wxPoint(120, 40));
txtSize = new wxTextCtrl(this, wxID_ANY, size, wxPoint(120, 70));
txtTime = new wxTextCtrl(this, wxID_ANY, time, wxPoint(120, 100));
txtDate = new wxTextCtrl(this, wxID_ANY, date, wxPoint(120, 130));
btnOk = new wxButton(this, 10004, "OK", wxPoint(80, 165));
btnCancel = new wxButton(this, 10005, "Cancel", wxPoint(155, 165));
}
// get values from text boxes and close
void ReservationDialog::Ok(wxCommandEvent& evt)
{
size = txtSize->GetValue().ToStdString();
time = txtTime->GetValue().ToStdString();
name = txtName->GetValue().ToStdString();
number = txtNumber->GetValue().ToStdString();
date = txtDate->GetValue().ToStdString();
Close();
evt.Skip();
}
// set values to default value and close
void ReservationDialog::Cancel(wxCommandEvent& evt)
{
canceled = true;
Close();
evt.Skip();
}

View File

@ -0,0 +1,35 @@
#pragma once
#include <wx/wx.h>
#include <string>
using namespace std;
class ReservationDialog : public wxDialog
{
public:
ReservationDialog();
ReservationDialog(string, string, string, string, string);
void Ok(wxCommandEvent&);
void Cancel(wxCommandEvent&);
wxTextEntry* txtName = nullptr;
wxTextEntry* txtNumber = nullptr;
wxTextEntry* txtSize = nullptr;
wxTextEntry* txtTime = nullptr;
wxTextEntry* txtDate = nullptr;
wxStaticText* lblName = nullptr;
wxStaticText* lblNumber = nullptr;
wxStaticText* lblSize = nullptr;
wxStaticText* lblTime = nullptr;
wxStaticText* lblDate = nullptr;
wxButton* btnOk = nullptr;
wxButton* btnCancel = nullptr;
string size, name, number, date, time;
bool canceled;
wxDECLARE_EVENT_TABLE();
};

View File

@ -0,0 +1,178 @@
#include "Restaurant.h"
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
Restaurant::Restaurant()
{
}
void Restaurant::addTable(int size)
{
Table t;
t.size = size;
tables.push_back(t);
}
bool Restaurant::reserveTable(int tNum)
{
return reserveTable(tNum, time(0));
}
bool Restaurant::reserveTable(int tNum, int time)
{
if (!isReserved(tNum, time))
{
Reservation r;
r.time = time;
tables.at(tNum).reservations.push_back(r);
return true;
}
return false;
}
void Restaurant::setFileName(string str)
{
fileName = str;
}
bool Restaurant::save()
{
if (fileName != "")
{
ofstream r;
r.open(fileName + ".txt");
r.clear();
r << "tables: " + tables.size() << endl;
for (int i = 0; i < tables.size(); i++)
{
r << "table: " << i << endl
<< "size: " << tables.at(i).size << endl
<< "reservations: " << tables.at(i).reservations.size() << endl;
for (int j = 0; j < tables.at(i).reservations.size(); j++)
{
r << tables.at(i).reservations.at(j).lastName << endl
<< tables.at(i).reservations.at(j).partySize << endl
<< tables.at(i).reservations.at(j).phoneNumber << endl
<< tables.at(i).reservations.at(j).time << endl;
}
}
r.close();
return true;
}
return false;
}
bool Restaurant::load(string fileName)
{
if (fileName != "")
{
tables.clear();
fstream r;
r.open(fileName + ".txt");
string line;
int tableCount;
}
return false;
}
// attempt to make a reservation for a party of <partySize> at <time> and return the index of the table that was reserved
int Restaurant::makeReservation(int partySize, int time, string name, string phoneNumber)
{
const int TOLERANCE = 2; // number of empty seats allowed at the table
for (int j = 0; j <= TOLERANCE; j++) // assign the party to the smallest table able to accomodate it
for (int i = 0; i < tables.size(); i++) // check each table to see if it meets desired parameters
// if the table can accomodate the party size within tolerance, make a reservation struct and append it to the tables list of reservations
if (tables.at(i).size == partySize + j && !isReserved(i, time))
{
Reservation r;
r.time = time;
r.partySize = partySize;
r.lastName = name;
r.phoneNumber = phoneNumber;
tables.at(i).reservations.push_back(r);
return i;
}
return -1; // return -1 as a flag to indicate no table could be reserved
}
int Restaurant::editReservation(int tNum, int resNum, int partySize, int time, std::string name, std::string number)
{
const int TOLERANCE = 2;
// clear the previous reservation
tables.at(tNum).reservations.erase(tables.at(tNum).reservations.begin() + resNum);
// create the new reservation
for (int j = 0; j <= TOLERANCE; j++)
for (int i = 0; i < tables.size(); i++)
if (tables.at(i).size == partySize + j && !isReserved(i, time))
{
Reservation r;
r.time = time;
r.partySize = partySize;
r.lastName = name;
r.phoneNumber = number;
tables.at(i).reservations.push_back(r);
return i;
}
return -1;
}
bool Restaurant::isReserved(int tNum)
{
return isReserved(tNum, time(0));
}
// check if a reservation starting at <time> will overlap any existing reservation slots for table <tNum>
bool Restaurant::isReserved(int tNum, int time)
{
vector<Reservation> reservations = tables.at(tNum).reservations;
for (int i = 0; i < reservations.size(); i++)
{
if (time + 3600 >= reservations.at(i).time && time <= reservations.at(i).time + 3600)
return true;
}
return false;
}
string Restaurant::tableStr(int tNum)
{
Table t = tables.at(tNum);
return "Table #" + to_string(tNum + 1) + " : " + to_string(t.size) + " : " + (isReserved(tNum) ? "Reserved" : "Not Reserved");
}
int Restaurant::waitTime(int partySize)
{
int timeOfOpening = -1;
const int TOLERANCE = 2; // number of empty seats allowed at the table
for (int j = 0; j <= TOLERANCE; j++) // assign the party to the smallest table able to accomodate it
for (int i = 0; i < tables.size(); i++) // check each table to see if it meets desired parameters
// if the table can accomodate the party size within tolerance
if (tables.at(i).size == partySize + j)
{
if (!isReserved(i))
return 0;
// make the next opening the new open time if it is the smallest so far
if (timeOfOpening == -1 || nextOpening(i) < timeOfOpening)
timeOfOpening = nextOpening(i);
}
return timeOfOpening;
}
// get the time of the next opening at the desired table
int Restaurant::nextOpening(int tNum)
{
int t = time(0);
Table table = tables.at(tNum);
for (int i = 0; i < table.reservations.size(); i++)
{
if (isReserved(tNum, t))
t = table.reservations.at(i).time + 3601;
else
return t;
}
return t;
}

View File

@ -0,0 +1,42 @@
#pragma once
#include <vector>
#include <string>
struct Reservation
{
int time;
int partySize;
std::string phoneNumber;
std::string lastName;
};
struct Table
{
std::vector<Reservation> reservations;
int occupants;
int size;
};
class Restaurant
{
public:
Restaurant();
void addTable(int);
bool reserveTable(int);
bool reserveTable(int, int);
int makeReservation(int, int, std::string, std::string);
int editReservation(int, int, int, int, std::string, std::string);
int waitTime(int);
int partyOf(int);
int nextOpening(int);
bool isReserved(int, int);
bool isReserved(int);
void setFileName(std::string);
bool save();
bool load(std::string);
std::string tableStr(int);
std::string fileName;
std::vector<Table> tables;
};

View File

@ -0,0 +1,18 @@
#include "cApp.h"
wxIMPLEMENT_APP(cApp);
cApp::cApp()
{
}
cApp::~cApp()
{
}
bool cApp::OnInit()
{
m_frame1 = new cMain();
m_frame1->Show();
return true;
}

View File

@ -0,0 +1,16 @@
#pragma once
#include <wx/wx.h>
#include "cMain.h"
class cApp : public wxApp
{
public:
cApp();
~cApp();
virtual bool OnInit();
private:
cMain* m_frame1 = nullptr;
};

View File

@ -0,0 +1,336 @@
#include "cMain.h"
#include <iostream>
#include "ReservationDialog.h"
#include <ctime>
#include <fstream>
using namespace std;
wxBEGIN_EVENT_TABLE(cMain, wxFrame)
EVT_BUTTON(10000, ReserveTable)
EVT_BUTTON(10001, AddTable)
EVT_BUTTON(10003, Edit)
EVT_BUTTON(10007, WaitTime)
EVT_LISTBOX(10002, ShowTable)
EVT_LISTBOX(10006, EnableEdits)
wxEND_EVENT_TABLE()
string formatTime(int);
string formatDate(int);
int toUnixTime(string);
int toUnixTime(string, string);
string ltrim(const string&);
string rtrim(const string&);
string trim(const string&);
const int DAY = 86400, HOUR = 3600, MIN = 60, TIMEZONE = -5;
cMain::cMain() : wxFrame(nullptr, wxID_ANY, "Restaurant Manager", wxPoint(300, 300), wxSize(400, 180),
wxMINIMIZE_BOX | wxSTATIC_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{
file = new wxMenu; file->Append(10007, "Save"); file->Append(10008, "Save As");
mnuMain = new wxMenuBar; mnuMain->Append(file, "&File");
//SetMenuBar(mnuMain);
btnParty = new wxButton(this, 10000, "Reservation", wxPoint(290, 105));
btnEdit = new wxButton(this, 10003, "Edit", wxPoint(290, 75), wxDefaultSize); btnEdit->Disable();
btnAddTable = new wxButton(this, 10001, "New Table", wxPoint(190, 105)); btnAddTable->SetFocus();
btnWaitTime = new wxButton(this, 10007, "Wait Time", wxPoint(190, 75));
lstTables = new wxListBox(this, 10002, wxPoint(20, 20), wxSize(150, 110));
lstReservations = new wxListBox(this, 10006, wxPoint(190, 20), wxSize(175, 50));
lblTable = new wxStaticText(this, wxID_ANY, "", wxPoint(190, 3), wxSize(100, 10));
lblTables = new wxStaticText(this, wxID_ANY, "Tables:", wxPoint(20, 3));
}
cMain::~cMain()
{
}
void cMain::AddTable(wxCommandEvent &evt)
{
// prompt user for table size
wxTextEntryDialog* msgAddTable = new wxTextEntryDialog(nullptr, "Size:", "Table Size", "");
msgAddTable->ShowModal();
wxString val = msgAddTable->GetValue();
string s = val.ToStdString();
// validate inpute
if (trim(s) != "")
{
restaurant.addTable(stoi(s)); // add table to restaurant
// update listbox text
lstTables->Clear();
for (int i = 0; i < restaurant.tables.size(); i++)
lstTables->AppendString(restaurant.tableStr(i));
}
evt.Skip();
}
void cMain::ShowTable(wxCommandEvent& evt)
{
// get selected item from list box
int pos = lstTables->GetSelection();
// update table label
if (pos >= 0)
{
Table table = restaurant.tables.at(pos);
lstReservations->Clear();
for (int i = 0; i < table.reservations.size(); i++)
lstReservations->AppendString(formatTime(table.reservations.at(i).time) + " to " + formatTime(table.reservations.at(i).time + 3600));
lblTable->SetLabel("Table #" + to_string(pos + 1) + ':');
}
btnEdit->Disable();
evt.Skip();
}
void cMain::Save(wxCommandEvent& evt)
{
restaurant.save();
}
// create a form to make a table reservation (also used to handle walk-ins)
void cMain::ReserveTable(wxCommandEvent& evt)
{
int pos = -1;
// create reservation form
ReservationDialog* msgReserveTable = new ReservationDialog();
msgReserveTable->ShowModal();
if (!msgReserveTable->canceled)
{
string val = trim(msgReserveTable->size);
string time = trim(msgReserveTable->time);
string date = trim(msgReserveTable->date);
string name = trim(msgReserveTable->name);
string phoneNumber = trim(msgReserveTable->number);
int unixTime = 0;
// assuming a party size is entered complete the form
if (val != "")
{
if (time != "")
if (date != "")
unixTime = toUnixTime(date, time);
else
unixTime = toUnixTime(time);
else
unixTime = std::time(0);
pos = restaurant.makeReservation(stoi(val), unixTime, name, phoneNumber);
}
if (pos < 0)
{
wxMessageDialog* msgNoRes = new wxMessageDialog(nullptr, "Unfortunately, the requested reservation could not be made.", "No Reservation");
msgNoRes->ShowModal();
}
lstTables->Clear();
for (int i = 0; i < restaurant.tables.size(); i++)
lstTables->AppendString(restaurant.tableStr(i));
btnEdit->Disable();
}
msgReserveTable->Destroy();
evt.Skip();
}
// edit a reservation
void cMain::Edit(wxCommandEvent& evt)
{
int pos = -1;
int tNum = lstTables->GetSelection(); tNum = (tNum >= 0) ? tNum : 0;
int resNum = lstReservations->GetSelection(); resNum = (resNum >= 0) ? resNum : 0;
Reservation r = restaurant.tables.at(tNum).reservations.at(resNum);
string name = r.lastName;
string phoneNumber = r.phoneNumber;
string size = to_string(r.partySize);
string time = formatTime(r.time);
string date = formatDate(r.time);
// create reservation form
ReservationDialog* msgReserveTable = new ReservationDialog(name, phoneNumber, size, time, date);
msgReserveTable->ShowModal();
if (!msgReserveTable->canceled)
{
name = trim(msgReserveTable->name);
phoneNumber = trim(msgReserveTable->number);
size = trim(msgReserveTable->size);
time = trim(msgReserveTable->time);
date = trim(msgReserveTable->date);
int unixTime = 0;
// assuming a party size is entered complete the form
if (size != "")
{
if (time != "")
if (date != "")
unixTime = toUnixTime(date, time);
else
unixTime = toUnixTime(time);
else
unixTime = std::time(0);
restaurant.editReservation(tNum, resNum, stoi(size), unixTime, name, phoneNumber);
}
if (pos >= 0)
{
Table table = restaurant.tables.at(pos);
string resData;
lstReservations->Clear();
for (int i = 0; i < table.reservations.size(); i++)
{
resData = table.reservations.at(i).lastName + ": ";
resData += formatTime(table.reservations.at(i).time) + " to " + formatTime(table.reservations.at(i).time + 3600);
lstReservations->AppendString(resData);
}
lblTable->SetLabel("Table #" + to_string(pos + 1) + ':');
}
lstTables->Clear();
for (int i = 0; i < restaurant.tables.size(); i++)
lstTables->AppendString(restaurant.tableStr(i));
}
msgReserveTable->Destroy();
evt.Skip();
}
void cMain::EnableEdits(wxCommandEvent& evt)
{
btnEdit->Enable();
}
void cMain::WaitTime(wxCommandEvent& evt)
{
int pos = -1;
// prompt user for party size
wxTextEntryDialog* msgWaitTime = new wxTextEntryDialog(nullptr, "Party Size:", "Wait Time", "");
msgWaitTime->ShowModal();
string val = msgWaitTime->GetValue().ToStdString();
if (val != "")
{
int wait = restaurant.waitTime(stoi(val));
// inform the user of a wait
if (wait > 0)
{
wxMessageDialog* msgWait = new wxMessageDialog(nullptr, "There is currently a wait until " + formatTime(wait), "Wait", wxOK);
msgWait->ShowModal();
}
else if (wait == 0)
{
wxMessageDialog* msgWait = new wxMessageDialog(nullptr, "There is currently no wait.", "Wait", wxOK);
msgWait->ShowModal();
}
// unsupported party size
else
{
wxMessageDialog* msgReservationError = new wxMessageDialog(nullptr, "Unfortunately, no tables can accomodate your party size.", "Reservation Error", wxOK | wxICON_ERROR);
msgReservationError->ShowModal();
}
}
}
string formatTime(int timestamp)
{
int days, hours, mins, secs;
string h, m, s;
days = timestamp / DAY; // find the number of days since 1970.01.01 00:00:00 GMT
timestamp -= days * DAY; // subtract that number of days worth of seconds
hours = timestamp / HOUR; // find the number of hours remaining
timestamp -= hours * HOUR; // subtract that number of hours in seconds
mins = timestamp / MIN; // find the number of minutes remaining
timestamp -= mins * MIN; // subtrace that number of minutes in seconds
secs = timestamp; // only seconds remain
hours = (hours + 24 + TIMEZONE) % 24; // convert to 24-hour time // make hours 12 when it is 0
h = to_string(hours); // convert hours to string
m = (to_string(mins).length() == 1 ? '0' + to_string(mins) : to_string(mins)); // add a leading 0 to minutes, if neccessary
s = (to_string(secs).length() == 1 ? '0' + to_string(secs) : to_string(secs)); // add a leading 0 to seconds, if neccessary
return h + ':' + m + ':' + s;
}
string formatDate(int timestamp)
{
timestamp += HOUR * TIMEZONE;
int months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // days in each month of the year
const float DAYS_PER_YEAR = 365.2425; // average number of days per year
int days = timestamp / DAY; // convert the timestamp from seconds to days
int year = days / DAYS_PER_YEAR; // convert the number of days into a number of years
days -= year * DAYS_PER_YEAR; // get the number of days left in the year
year += 1970; // add 1970 to the year, since UNIX time starts at the beginning of 1970
int day = 0, month = 0;
months[1] += !(year % 4) && (bool(year % 100) != !(year % 400)); // add a day to February if its a leap year
for (int i = 0; i < 12; i++)
{
month += 1; // incrament the month
day += months[i]; // incrament the number of days since the beginning of the year
if (days <= day) // check if the month is correct
{
day = months[i] - (day - days) + 1; // get the day of the month
break;
}
}
return to_string(month) + '/' + to_string(day) + '/' + to_string(year); // return in mm/dd/yyyy format
}
int toUnixTime(string time)
{
int today = std::time(0) - (std::time(0) % 86400);
if (time.find(':') == time.rfind(':'))
time += ":00";
int hours = stoi(time.substr(0, time.find(':'))) - TIMEZONE;
int mins = stoi(time.substr(time.find(':') + 1, time.rfind(':')));
int secs = stoi(time.substr(time.rfind(':') + 1));
return today + hours*3600 + mins*60 + secs;
}
int toUnixTime(string date, string time)
{
int t = 0;
int year = stoi(date.substr(date.rfind('/') + 1));
int day = stoi(date.substr(date.find('/') + 1, 2));
int month = stoi(date.substr(0, date.find('/')));
if (time.find(':') == time.rfind(':'))
time += ":00";
int hours = stoi(time.substr(0, time.find(':'))) - TIMEZONE;
int mins = stoi(time.substr(time.find(':') + 1, time.rfind(':')));
int secs = stoi(time.substr(time.rfind(':') + 1));
//Convert years to days
t = (365 * year) + (year / 4) - (year / 100) + (year / 400);
//Convert months to days
t += (30 * month) + (3 * (month + 1) / 5) + day;
//Unix time starts on January 1st, 1970
t -= 719561;
//Convert days to seconds
t *= 86400;
//Convert hours to seconds
t += hours * 3600;
//Convert minutes to seconds
t += mins * 60 + secs;
return t;
}
const string WHITESPACE = " \n\r\t\f\v";
string ltrim(const string& s)
{
size_t start = s.find_first_not_of(WHITESPACE);
return (start == string::npos) ? "" : s.substr(start);
}
string rtrim(const string& s)
{
size_t end = s.find_last_not_of(WHITESPACE);
return (end == string::npos) ? "" : s.substr(0, end + 1);
}
string trim(const string& s) {
return rtrim(ltrim(s));
}

View File

@ -0,0 +1,35 @@
#pragma once
#include "wx/wx.h"
#include "Restaurant.h"
class cMain : public wxFrame
{
public:
cMain();
~cMain();
public:
wxButton* btnParty = nullptr;
wxButton* btnEdit = nullptr;
wxButton* btnClear = nullptr;
wxButton* btnAddTable = nullptr;
wxButton* btnWaitTime = nullptr;
wxListBox* lstTables = nullptr;
wxListBox* lstReservations = nullptr;
wxStaticText* lblTable = nullptr;
wxStaticText* lblTables = nullptr;
wxMenuBar* mnuMain = nullptr;
wxMenu* file = nullptr;
Restaurant restaurant = Restaurant();
void AddTable(wxCommandEvent& evt);
void ShowTable(wxCommandEvent& evt);
void ReserveTable(wxCommandEvent& evt);
void EnableEdits(wxCommandEvent& evt);
void Edit(wxCommandEvent& evt);
void Save(wxCommandEvent& evt);
void WaitTime(wxCommandEvent& evt);
wxDECLARE_EVENT_TABLE();
};

View File

@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by wxBase.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

View File

@ -0,0 +1,4 @@
ables:
table: 0
size: 5
reservations: 0

View File

@ -0,0 +1,60 @@
// 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 9, 1
#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
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,165 @@
<?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>
<ItemGroup>
<ClInclude Include="cApp.h" />
<ClInclude Include="cMain.h" />
<ClInclude Include="ReservationDialog.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Restaurant.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="cApp.cpp" />
<ClCompile Include="cMain.cpp" />
<ClCompile Include="ReservationDialog.cpp" />
<ClCompile Include="Restaurant.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="wxBase.rc" />
</ItemGroup>
<ItemGroup>
<Text Include="README.txt" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{128b02c4-4e1c-4f63-8a0a-b32dd6b4a54b}</ProjectGuid>
<RootNamespace>wxBase</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>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</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;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</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;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</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;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(WXWIN)\include;$(WXWIN)\include\msvc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(WXWIN)\lib\vc_lib;</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,56 @@
<?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>
<ClInclude Include="cApp.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="cMain.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Restaurant.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ReservationDialog.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="cApp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cMain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Restaurant.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ReservationDialog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="wxBase.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Text Include="README.txt" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -0,0 +1,28 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 9/22/2021
* File Name: Homework1-1ASharpe.cpp
*****************************************************************
* ID: Homework 1 Problem 1
* Purpose: Estimate the revenue generated by a specific division of a corporation.
*****************************************************************/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
const float PERCENT_TOTAL_SALES = .58;
const int SALES = 86000000;
float divisionRevenue = PERCENT_TOTAL_SALES * SALES; // calculate the revenue estimate for the east coast division
cout << fixed << setprecision(2) << "The East Coast Division generated $" << divisionRevenue << " in sales";
return 0;
}

View File

@ -0,0 +1,39 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: <date>
* File Name: <filename>.cpp
*****************************************************************
* ID: Homework 1 Problem 2
* Purpose: Calculate the tax and total cost of a purchase given sales tax and the subtotal
*****************************************************************/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
const float STATE_SALES_TAX = .065, COUNTY_SALES_TAX = 0.02;
float subtotal, tax, total;
// get price of purchase
cout << "Price of purchase: ";
cin >> subtotal;
tax = subtotal * (STATE_SALES_TAX + COUNTY_SALES_TAX); // calculate tax
total = subtotal + tax; // calculate total price
cout << fixed << setprecision(3) << endl; // format the costs to 3 decimal places to account for sales tax precision errors
// print data
cout << "Subtotal: $" << subtotal << endl;
cout << "Tax: $" << tax << endl;
cout << "Total: $" << total;
return 0;
}

View File

@ -0,0 +1,40 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 09.30.2021
* File Name: Homework02-1ASharpe.cpp
*****************************************************************
* ID: Homework 2 Problem 1
* Purpose: Calculate total monthly and yearly costs of several expenses
*****************************************************************/
#include <iostream>
using namespace std;
int main()
{
int monthlyCost = 0, cost; // initialize montlyCost to 0 to prevent propagation of arbitrary values
cout << "Enter the following costs:" << endl << "Rent/Mortgage: ";
cin >> cost; // set cost to cost of Rent/Mortgage payment
monthlyCost += cost; // add Rent/Mortgage payment to monthly cost
cout << "Phones: ";
cin >> cost; // set cost to cost of Phone payment
monthlyCost += cost; // add Phone payment to monthly cost
cout << "Internet: ";
cin >> cost; // set cost to cost of Internet payment
monthlyCost += cost; // add Internet payment to monthly cost
cout << "Cable: ";
cin >> cost; // set cost to cost of Cable payment
monthlyCost += cost; // add Cable payment to monthly cost
cout << "\nTotal Monthly cost: " << monthlyCost << endl
<< "Total Yearly cost: " << 12 * monthlyCost;
return 0;
}

View File

@ -0,0 +1,35 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 10.11.2021
* File Name: Homework3-1ASharpe.cpp
*****************************************************************
* ID: Homework 3 Problem 1
* Purpose: Compare the sizes of two rectangles
*****************************************************************/
#include <iostream>
using namespace std;
int main()
{
int areas[2];
for ( int i = 0; i < 2; i++ )
{
int width, height;
cout << "Enter width: ";
cin >> width;
cout << "Enter height: ";
cin >> height;
areas[i] = width * height; // set area of rectangle
}
// figure out which rectangle has the larger area (if any) and print the result
cout << ((areas[0] > areas[1]) ? "Rect 1 is bigger." : (areas[1] > areas[0]) ? "Rect 2 is bigger." : "They are the same size.");
return 0;
}

View File

@ -0,0 +1,25 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 10.11.2021
* File Name: Homework04-1ASharpe.cpp
*****************************************************************
* ID: Homework 4 Problem 1
* Purpose: Display ASCII characters 32-127
*****************************************************************/
#include <iostream>
using namespace std;
int main()
{
for ( int i = 32; i < 128; i++) // for characters 32-127
{
if (!(i % 16)) // newline after every 16 ASCII chars
cout << endl;
cout << char(i) << ' '; // print the ASCII char followed by a space
}
return 0;
}

View File

@ -0,0 +1,41 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 10.11.2021
* File Name: Homework04-2ASharpe.cpp
*****************************************************************
* ID: Homework 4 Problem 2
* Purpose: Display distance covered at different time periods
*****************************************************************/
#include <iostream>
using namespace std;
int main()
{
int mph, time;
// get user inputs
cout << "Enter speed in MPH: ";
cin >> mph;
cout << "Enter time of trip in hours: ";
cin >> time;
// formatting things
cout << "*********************************" << endl;
cout << "* Hour\t* Miles Traveled\t*" << endl;
cout << "*********************************" << endl;
// distance traveled after each hour
for (int i = 0; i < time; i++)
{
cout << "* " << i << "\t* " << i * mph << "\t\t\t*" << endl;
}
// more formatty things
cout << "*********************************" << endl;
return 0;
}

View File

@ -0,0 +1,59 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 10.18.2021
* File Name: Homework05-1ASharpe.cpp
*****************************************************************
* ID: Homework 5 Problem 1
* Purpose: Simulate a population for N years
*****************************************************************/
#include <iostream>
#include <cmath>
using namespace std;
int getPopAfterNYears(int, float, float, int);
int main()
{
int pop, time;
float birthRate, deathRate;
// get population data
do
{
cout << "Original population size: ";
cin >> pop;
} while ( pop < 2 ); // ensure that population is at least 2
do
{
cout << "Birth rate: ";
cin >> birthRate;
} while ( static_cast<int>(birthRate) != 0 ); // make sure birthRate is between 0 and 1
do
{
cout << "Death rate: ";
cin >> deathRate;
} while ( static_cast<int>(deathRate) != 0 ); // make sure deathRate is between 0 and 1
do
{
cout << "Time: ";
cin >> time;
} while ( time < 1 ); // ensure that time is at least 1 year
// calculate & print the new population size after "time" years
// note that pop is an int, so it will only increase
cout << "Population after " << time << " years: " << getPopAfterNYears(pop, birthRate, deathRate, time);
return 0;
}
int getPopAfterNYears(int pop, float birthRate, float deathRate, int time)
{
// find new population size for each year in the time range
for (; time > 0; time--)
pop = pop * (1 + birthRate) * (1 - deathRate);
return pop;
}

View File

@ -0,0 +1,55 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 10.18.2021
* File Name: Homework05-1ASharpe.cpp
*****************************************************************
* ID: Homework 5 Problem 1
* Purpose: Simulate a population for N years
*****************************************************************/
#include <iostream>
#include <cmath>
using namespace std;
void simulateForNYears(int&, float, float, int);
int main()
{
int pop, time;
float birthRate, deathRate;
// get population data
do
{
cout << "Original population size: ";
cin >> pop;
} while ( pop < 2 );
cout << "Birth rate: ";
cin >> birthRate;
cout << "Death rate: ";
cin >> deathRate;
do
{
cout << "Time: ";
cin >> time;
} while ( time < 1 );
// run simulation
// note that pop is passed by reference
simulateForNYears(pop, birthRate, deathRate, time);
// print the new population size after "time" years
// note that pop is an int, so it will only increase
cout << "Population after " << time << " years: " << pop;
return 0;
}
void simulateForNYears(int& pop, float birthRate, float deathRate, int time)
{
// find new population size for each year in the time range
for (; time > 0; time--)
pop = pop * (1 + birthRate) * (1 - deathRate);
}

View File

@ -0,0 +1,79 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 11.08.2021
* File Name: Homework6-1ASharpe.cpp
*****************************************************************
* ID: Homework 6 Problem 1
* Purpose: Calculate the total cost of a hospital visit
*****************************************************************/
#include <iostream>
using namespace std;
bool isInvalidInput(int);
int totalCharge(int, int, int, int);
int totalCharge(int, int);
int main()
{
char inpatient;
bool isInpatient;
int days, dailyRate, serviceFees, medFees;
// check if patient stayed multiple days
cout << "Inpatient? (y/n): ";
cin >> inpatient;
isInpatient = inpatient == 'y';
// get and validate cost data
if (isInpatient)
{
do
{
cout << "Days spent: ";
cin >> days;
} while (isInvalidInput(days));
do
{
cout << "Daily rate: ";
cin >> dailyRate;
} while (isInvalidInput(dailyRate));
}
do
{
cout << "Total Service Fees: ";
cin >> serviceFees;
} while (isInvalidInput(serviceFees));
do
{
cout << "Total Medication Fees: ";
cin >> medFees;
} while(isInvalidInput(medFees));
// output total cost
cout << "\nYour total cost is $";
if (isInpatient)
cout << totalCharge(days, dailyRate, serviceFees, medFees);
else
cout << totalCharge(serviceFees, medFees);
return 0;
}
int totalCharge(int days, int dailyRate, int serviceFees, int medFees)
{
return days*dailyRate + serviceFees + medFees;
}
int totalCharge(int serviceFees, int medFees)
{
return serviceFees + medFees;
}
// valid inputs are >= 0
bool isInvalidInput(int in)
{
return in < 0;
}

Binary file not shown.

View File

@ -0,0 +1,26 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 2
* Assignment Date: 9/15/2021
* File Name: Lab01-1ASharpe.cpp
*****************************************************************
* ID: Lab 1 Problem 1
* Purpose: Print the value of paychecks with given pay periods and salary
*****************************************************************/
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int ANNUAL_PAY = 39000, TWICE_MONTHLY = 24, BI_WEEKLY = 26;
//Print paycheck value with both twice monthly payment and bi-weekly payment
cout << endl << "Paycheck value at $" << ANNUAL_PAY << " per year with " << TWICE_MONTHLY << " paychecks per year: $" << ( ANNUAL_PAY / TWICE_MONTHLY ) << endl
<< "Paycheck value at $" << ANNUAL_PAY << " per year with " << BI_WEEKLY << " paychecks per year: $" << ( ANNUAL_PAY / BI_WEEKLY ) << endl;
return 0;
}

View File

@ -0,0 +1,27 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 2
* Assignment Date: 9/15/2021
* File Name: Lab01-2ASharpe.cpp
*****************************************************************
* ID: Lab 1 Problem 2
* Purpose: Calculate how many energy drinks and citrus drinks are being consumed out of a set of customers
*****************************************************************/
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int CUSTOMERS = 16500;
const float ENERGY_PERCENT = 0.15, CITRUS_PERCENT = 0.52;
//Calculate the number of customers that got energy drinks and the number that got citrus drinks
cout << endl << "Out of " << CUSTOMERS << " customers: about " << int( ENERGY_PERCENT * CUSTOMERS ) << " had an energy drink, "
<< "and about " << int( CITRUS_PERCENT * CUSTOMERS ) << " had a citrus drink." << endl;
return 0;
}

View File

@ -0,0 +1,35 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 09.29.2021
* File Name: Lab03-1ASharpe.cpp
*****************************************************************
* ID: Lab 3 Problem 1
* Purpose: Determine and print whether or not a given year is a leap year
*****************************************************************/
#include <iostream>
using namespace std;
int main()
{
int year;
// ask the user for a year
cout << "Enter a year: ";
cin >> year;
// cout << "\n\n";
// determine if the year is a leap year
// if
// cout << year << " is a leap year.";
// else
// cout << year << " is not a leap year.";
cout << " is" << (( year >= 1582 && (year % 100 != 0 || year % 400 == 0) && year % 4 == 0) ? " " : " not ") << "a leap year.";
return 0;
}

View File

@ -0,0 +1,43 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 09.29.2021
* File Name: Lab03-2ASharpe.cpp
*****************************************************************
* ID: Lab 3 Problem 2
* Purpose: Computes and prints the price of a speeding ticket given a car speed in a 55 Mph zone
*****************************************************************/
#include <iostream>
using namespace std;
int main()
{
const int SPEED_LIMIT = 55;
int speed;
// ask the cop for the speed of the vehicle
cout << "Enter the speed between 0 and 150 Mph: ";
cin >> speed;
cout << "\n\n";
// determine the cost of the ticket if the driver was speeding
if ( speed > SPEED_LIMIT && speed < 150 )
// determine which ticket cost range applies
if ( speed - (SPEED_LIMIT + 20) >= 0)
cout << "The price of the ticket is $" << 50 + 5 * (speed - SPEED_LIMIT);
else
cout << "The price of the ticket is $" << 50 + 2 * (speed - SPEED_LIMIT);
// determine if the vehicle was actually speeding
else if ( speed <= SPEED_LIMIT )
cout << "The driver was not speeding.";
// if the driver is reckless
else
cout << "The driver should be arrested.";
return 0;
}

View File

@ -0,0 +1,75 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 10.06.2021
* File Name: Lab04-1ASharpe.cpp
*****************************************************************
* ID: Lab 4 Problem 1
* Purpose: Run an election machine simulation
*****************************************************************/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
bool voting = true, firstAttempt = true;
const string candidate1 = "Donald Trump", candidate2 = "Joe Biden"; // names of the candidates
int vote = 0;
int votes[2] = {0, 0}; // votes for each of the two candidates
ofstream outFile;
outFile.open("results.txt");
while ( voting )
{
firstAttempt = true;
vote = -1;
do
{
// voter intro screen
if ( firstAttempt )
cout << "\n\n\n"
<< "***********************************************************************\n"
<< "* WELCOME TO THE 2020 ELECTION *\n"
<< "***********************************************************************\n";
// invalid input instructions
else
cout << "\nWARNING: you have entered an invalid selection. Valid selections include (1), (2)\n";
// voter instructions
cout << "Please select (1) to vote for " << candidate1 << " (2) to vote for " << candidate2 << " :";
cin >> vote;
// break condition
if (vote == 999)
{
voting = false;
// put the results in a file
outFile << candidate1 + ": " + to_string(votes[0]) + "\n" + candidate2 + ": " + to_string(votes[1]);
outFile.close();
break;
}
firstAttempt = false;
} while (vote != 1 && vote != 2);
votes[0] += (vote == 1) ? 1 : 0; // conditionally incrament candidate 1
votes[1] += (vote == 2) ? 1 : 0; // conditionally incrament candidate 2
}
// voting results screen
cout << "\n\n\n"
<< "***********************************************************************\n"
<< "* 2020 ELECTION RESULTS *\n"
<< "***********************************************************************\n";
cout << endl << candidate1 << ": " << votes[0] << "\t\t\t" << candidate2 << ": " << votes[1] << endl;
return 0;
}

View File

@ -0,0 +1,2 @@
Donald Trump: 4
Joe Biden: 2

View File

@ -0,0 +1,60 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 10.13.2021
* File Name: Lab05-1ASharpe.cpp
*****************************************************************
* ID: Lab 5 Problem 1
* Purpose: Calculate the average miles per gallon of 3 planes over a 1000 mile flight
*****************************************************************/
#include <iostream>
#include <string>
using namespace std;
float calcMPG(float miles, float gallons);
int main()
{
string make, model, mostEfficientPlane;
float gallonsUsed, milesPerGallon, mostEfficientMPG = -1;
const float FLIGHT_DISTANCE = 1000;
const int PLANES = 3;
for(int i = 0; i < PLANES; i++)
{
cout << endl << "Enter the make and model of plane #" << i+1 << ": ";
cin >> make;
cin >> model;
do
{
cout << "Enter the number of gallons used during the 1000mi flight: ";
cin >> gallonsUsed;
} while (gallonsUsed <= 0); // make sure that the user enters a valid number of gallons consumed
// calculate the miles per gallon
milesPerGallon = calcMPG(FLIGHT_DISTANCE, gallonsUsed);
// determine if the current plane is the most efficient one so far
if (mostEfficientMPG == -1 || milesPerGallon > mostEfficientMPG)
{
mostEfficientMPG = milesPerGallon;
mostEfficientPlane = make + ' ' + model;
}
// display the MPG for the current plane
cout << "The average MPG of the " << make << ' ' << model << " is " << milesPerGallon << '.' << endl;
}
// display the most fuel efficient plane
cout << endl << "The most efficient plane was the " << mostEfficientPlane << " with an MPG of " << mostEfficientMPG << '.';
return 0;
}
// function to calculate miles per gallon
float calcMPG(float miles, float gallons)
{
return miles/gallons;
}

View File

@ -0,0 +1,44 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 10.13.2021
* File Name: Lab05-2ASharpe.cpp
*****************************************************************
* ID: Lab 5 Problem 2
* Purpose: Calculate the profit made from stocks
*****************************************************************/
#include <iostream>
using namespace std;
float profit(float NS, float SP, float SC, float PP, float PC);
int main(int argc, char const *argv[])
{
float NS, SP, SC, PP, PC;
// get investment information
cout << "Number of shares: ";
cin >> NS;
cout << "Sale price per share: ";
cin >> SP;
cout << "Sale commission paid: ";
cin >> SC;
cout << "Purchase price per share: ";
cin >> PP;
cout << "Purchase commission paid: ";
cin >> PC;
// display profit or loss
cout << endl << "The profit on the investment was $" << profit(NS, SP, SC, PP, PC);
return 0;
}
// calculate the profit of an investment
float profit(float NS, float SP, float SC, float PP, float PC)
{
return ((NS * SP) - SC) - ((NS * PP) + PC);
}

View File

@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}

View File

@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

View File

@ -0,0 +1,14 @@
#include <iostream>
#include "GradeMenu.h"
using namespace std;
// display the selection menu and prompt the user
void GradeMenu::displayMenu()
{
cout << "1. Enter student and grade information" << endl
<< "2. Adjust student grade information" << endl
<< "3. Display sudent grades" << endl
<< "4. Exit" << endl << endl
<< ">>> ";
}

View File

@ -0,0 +1,11 @@
#ifndef GRADEMENU_H
#define GRADEMENU_H
class GradeMenu
{
public:
void displayMenu();
Counter();
};
#endif

Binary file not shown.

View File

@ -0,0 +1,105 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 10.27.2021
* File Name: main.cpp
*****************************************************************
* ID: Lab 6 Problem 1
* Purpose: Manage the grades of 3 students
*****************************************************************/
#include <iostream>
#include <string>
#include "GradeMenu.h"
using namespace std;
void enterGrades(struct Student[]);
void adjustGrades(struct Student[]);
void displayGrades(struct Student[]);
struct Student
{
string name;
int classId;
float grade;
};
int main()
{
int selection = 1;
char tryAgain;
Student students[3];
GradeMenu gm = GradeMenu();
do
{
// display the selection menu
gm.displayMenu();
cin >> selection;
// clear the screen and continue
system("clear");
switch (selection)
{
case 1:
enterGrades(students);
break;
case 2:
adjustGrades(students);
break;
case 3:
displayGrades(students);
break;
case 4:
return 0;
// if the entry is invalid, the default case will execute
default:
cout << "INVALID INPUT: please enter a value between 1 and 4. Input c to try again." << endl;
cin >> tryAgain;
if (tryAgain != 'c')
return 0;
}
} while (true); // run until the user exits the program or does not try again after invalid input
}
// edit all properties of each student
void enterGrades(Student students[])
{
for(int i = 0; i < 3; i++)
{
cout << endl << "Full Name: ";
cin.ignore();
getline(cin, students[i].name);
cout << "Class ID: ";
cin >> students[i].classId;
cout << "Grade: ";
cin >> students[i].grade;
}
}
// loop through each student in the list and update his grade
void adjustGrades(Student students[])
{
for(int i = 0; i < 3; i++)
{
cout << "New Grade for " << students[i].name << ": ";
cin >> students[i].grade;
cout << endl;
}
}
// display the grade of each student
void displayGrades(Student students[])
{
for(int i = 0; i < 3; i++)
{
cout << "Student ID: " << i + 1 << endl
<< "Full Name: " << students[i].name << endl
<< "Grade: " << students[i].grade << endl
<< "Class ID: " << students[i].classId << endl << endl;
}
}

View File

@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x86"
}
],
"version": 4
}

View File

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

View File

@ -0,0 +1,130 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 11/3/2021
* File Name: Lab07-1ASharpe.cpp
*****************************************************************
* ID: Lab 7 Problem 1
* Purpose: Use an array of structs to simulate an inventory management system
*****************************************************************/
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
struct item
{
int skuNo;
int qty;
};
void randomizeInventory(item[]);
void selectionSort(item[]);
void swap(item&, item&);
int binarySearch(const item[], int);
int main()
{
int sku, pos;
string go;
item inventory[1000];
randomizeInventory(inventory);
selectionSort(inventory);
// print the first skuNo so we can test for items that are actually carried
cout << "Welcome to Aidan's not-sketchy-at-all store!!!" << endl
<< "Enter the SKU number of the item you are looking for to see if we have it in stock." << endl
<< "The SKU of the element at index 500 is " << inventory[500].skuNo << endl;
do
{
cout << endl << "SKU #";
cin >> sku;
pos = binarySearch(inventory, sku);
// check if the item is carried in inventory and print how many are carried if it is
if (pos != -1)
cout << "We currently have " << inventory[pos].qty << " of this item." << endl;
else
cout << "Sorry, we do not carry this item." << endl;
cout << endl << "Enter <c> to continue searching.";
cin.ignore();
getline(cin, go);
} while (go == "c");
}
// randomize the items that are carried in inventory
void randomizeInventory(item inventory[])
{
srand( time(0) );
for (int i = 0; i < 1000; i++)
{
inventory[i].skuNo = rand() % 99999999 + 1;
inventory[i].qty = rand() % 100 + 1;
}
}
// sort the array by skuNo
void selectionSort(item array[])
{
int minIndex, minValue, size = 1000;
for(int start = 0; start < (size - 1); start++)
{
minIndex = start;
minValue = array[start].skuNo;
for(int index = start + 1; index < size; index++)
{
if(array[index].skuNo < minValue)
{
minValue = array[index].skuNo;
minIndex = index;
}
}
swap(array[minIndex], array[start]);
}
}
// swap two inventory items
void swap(item& a, item& b)
{
item temp = a;
a = b;
b = temp;
}
// return the position of the item with skuNo <value>
int binarySearch(const item array[], int value)
{
int size = 1000,
first = 0,
last = size - 1,
middle,
position = -1;
bool found = false;
while(!found && first <= last)
{
middle = (first + last) / 2;
if (array[middle].skuNo == value)
{
found = true;
position = middle;
}
else if(array[middle].skuNo > value)
last = middle - 1;
else
first = middle + 1;
}
return position;
}

Binary file not shown.

View File

@ -0,0 +1,91 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 11.10.2021
* File Name: Lab8-1ASharpe.cpp
*****************************************************************
* ID: Lab 8 Problem 1
* Purpose: Get and sort a list of speeds from the user
*****************************************************************/
#include <iostream>
#include <string>
using namespace std;
void sort(float[], int);
float mean(float[], int);
int main()
{
int numSpeeds;
cout << string(37, '*') << endl
<< "* WELCOME TO THE DMV SPEED CENTER *" << endl
<< string(37,'*') << endl;
// get number of speed values
do
{
cout << "Number of speeds to store: ";
cin >> numSpeeds;
} while (numSpeeds <= 0);
float speeds[numSpeeds];
// get all speed values
for(int i=0; i < numSpeeds; i++)
{
do
{
cout << "Speed " << i + 1 << ": ";
cin >> speeds[i];
} while (speeds[i] < 0);
}
// sort the speeds and display the sorted array
sort(speeds, numSpeeds);
cout << "\nSorted speeds are:" << endl;
for(int i=0; i<numSpeeds; i++)
cout << speeds[i] << ' ';
cout << "\n\nAverage of " << numSpeeds << " speeds is: " << mean(speeds, numSpeeds);
return 0;
}
// use selection sort to sort an array of floats of length <size> from least to greatest
void sort(float array[], int size)
{
int minIndex;
float minValue;
for(int start = 0; start < (size - 1); start++)
{
minIndex = start;
minValue = array[start];
for(int index = start + 1; index < size; index++)
{
if(array[index] < minValue)
{
minValue = array[index];
minIndex = index;
}
}
// swap
float temp = array[minIndex];
array[minIndex] = array[start];
array[start] = temp;
}
}
// find and return the mean of an array of floats of length size
float mean(float array[], int length)
{
float sum = 0;
for(int i=0; i<length; i++)
sum += array[i];
return sum / length;
}

Binary file not shown.

View File

@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}

View File

@ -0,0 +1,6 @@
{
"C_Cpp.errorSquiggles": "Enabled",
"files.associations": {
"array": "cpp"
}
}

View File

@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

View File

@ -0,0 +1,70 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 11.17.2021
* File Name: Lab09-1ASharpe.cpp
*****************************************************************
* ID: Lab 9 Problem 1
* Purpose: Collect scores in a dynamically allocated array
*****************************************************************/
#include <iostream>
using namespace std;
void sort(int*, int);
int main()
{
int length, total = 0;
cout << "Please enter the number of test scores: ";
cin >> length;
int *scores = new int[length];
for(int i = 0; i < length; i++)
{
cout << "Please enter the score No. " << i << ": ";
cin >> *(scores + i);
}
sort(scores, length);
cout << "The scores in ascending order are:";
for(int i = 0; i < length; i++)
{
cout << ' ' << *(scores + i);
total += *(scores + i);
}
cout << "\nAverage score: " << total / length;
delete scores;
return 0;
}
void sort(int* ptr, int size)
{
int minIndex, minValue;
for(int start = 0; start < (size - 1); start++)
{
minIndex = start;
minValue = *(ptr + start);
for(int index = start + 1; index < size; index++)
{
if(*(ptr + index) < minValue)
{
minValue = *(ptr + index);
minIndex = index;
}
}
// swap
int temp = *(ptr + minIndex);
*(ptr + minIndex) = *(ptr + start);
*(ptr + start) = temp;
}
}

View File

@ -0,0 +1,32 @@
#include "Counter.h"
#include <climits>
// Counter::Counter()
// {
// maxValue = INT_MAX;
// }
void Counter::setCount(int num)
{
value = num;
}
void Counter::increment()
{
++value;
}
void Counter::decrement()
{
--value;
}
int Counter::getCount()
{
return value;
}
int Counter::getMaxValue()
{
return maxValue;
}

View File

@ -0,0 +1,13 @@
#define COUNTER_H
class Counter
{
private:
int value, maxValue;
public:
void setCount(int);
void increment();
void decrement();
int getCount();
int getMaxValue();
};

View File

@ -0,0 +1,27 @@
#include <iostream>
#include "Counter.h"
using namespace std;
int main()
{
Counter c = Counter();
int num;
cout << "The current count is " << c.getCount() << endl; // show that we can get the count
cout << "Enter a new number for the count: "; // show that we can change the count
cin >> num;
c.setCount(num);
cout << "The new count is " << c.getCount() << endl;
cout << "Incramenting the count..." << endl; // show that we can increment the count
c.increment();
cout << "The new count is " << c.getCount() << endl;
cout << "Decrementing the count..." << endl; // show that we can decrement the count
c.decrement();
cout << "The new count is " << c.getCount() << endl;
return 0;
}

View File

@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}

View File

@ -0,0 +1,27 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

View File

@ -0,0 +1,29 @@
#include <iostream>
#include <string>
using namespace std;
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, can be removed
return y;
}
int main()
{
int number;
cin >> number;
cout << Q_rsqrt( number );
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,11 @@
{
"Version": 1,
"ProjectMap": {
"17c6f123-4fbb-4f4d-838d-26a2a9b1c39e": {
"ProjectGuid": "17c6f123-4fbb-4f4d-838d-26a2a9b1c39e",
"DisplayName": "Lab10-1ASharpe",
"ColorIndex": 0
}
},
"NextColorIndex": 1
}

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lab10-1ASharpe", "Lab10-1ASharpe\Lab10-1ASharpe.vcxproj", "{17C6F123-4FBB-4F4D-838D-26A2A9B1C39E}"
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
{17C6F123-4FBB-4F4D-838D-26A2A9B1C39E}.Debug|x64.ActiveCfg = Debug|x64
{17C6F123-4FBB-4F4D-838D-26A2A9B1C39E}.Debug|x64.Build.0 = Debug|x64
{17C6F123-4FBB-4F4D-838D-26A2A9B1C39E}.Debug|x86.ActiveCfg = Debug|Win32
{17C6F123-4FBB-4F4D-838D-26A2A9B1C39E}.Debug|x86.Build.0 = Debug|Win32
{17C6F123-4FBB-4F4D-838D-26A2A9B1C39E}.Release|x64.ActiveCfg = Release|x64
{17C6F123-4FBB-4F4D-838D-26A2A9B1C39E}.Release|x64.Build.0 = Release|x64
{17C6F123-4FBB-4F4D-838D-26A2A9B1C39E}.Release|x86.ActiveCfg = Release|Win32
{17C6F123-4FBB-4F4D-838D-26A2A9B1C39E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {554E6C7D-29E3-4410-98C5-88DAB7928C5A}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,35 @@
/***************************************************************
* Name: Aidan Sharpe
* Course: Computer Science & Programming
* Class: CS04103 Section: 6
* Assignment Date: 2021.12.01
* File Name: Lab10-1ASharpe.cpp
*****************************************************************
* ID: Lab 0 Problem 1
* Purpose: Playing with cstrings
*****************************************************************/
#include <iostream>
using namespace std;
int main()
{
char fName[10], mName[10], mlName[10], lName[10], fullName[80];
cout << "Enter your first name: ";
cin >> fName;
cout << "Enter your middle name: ";
cin >> mName;
cout << "Enter your maiden name: ";
cin >> mlName;
cout << "Enter your husbands last name: ";
cin >> lName;
strcpy(fullName, lName);
strcat(fullName, ", ");
strcat(fullName, fName);
strcat(fullName, " ");
strcat(fullName, mName);
cout << "\nYour married name is: " << fullName;
}

View File

@ -0,0 +1,147 @@
<?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>{17c6f123-4fbb-4f4d-838d-26a2a9b1c39e}</ProjectGuid>
<RootNamespace>Lab101ASharpe</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>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</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="Lab10-1ASharpe.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,22 @@
<?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="Lab10-1ASharpe.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\Aidan\OneDrive - Rowan University\Fall 2021\CSNP\Lab #10\Lab10-1ASharpe\x64\Debug\Lab10-1ASharpe.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

View File

@ -0,0 +1,2 @@
 Lab10-1ASharpe.cpp
Lab10-1ASharpe.vcxproj -> C:\Users\Aidan\OneDrive - Rowan University\Fall 2021\CSNP\Lab #10\Lab10-1ASharpe\x64\Debug\Lab10-1ASharpe.exe

View File

@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.30.30705:TargetPlatformVersion=10.0.19041.0:VcpkgTriplet=x64-windows:
Debug|x64|C:\Users\Aidan\OneDrive - Rowan University\Fall 2021\CSNP\Lab #10\Lab10-1ASharpe\|

Some files were not shown because too many files have changed in this diff Show More