added old projects

This commit is contained in:
Austin Bennett
2026-02-03 08:18:39 -06:00
parent 43acf989bf
commit 2451448b8a
623 changed files with 28117 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
View File
+28
View File
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
+28
View File
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
+46
View File
@@ -0,0 +1,46 @@
#include <iostream>
#include <climits>
#include <string>
template<typename inputType>
inputType ReadValue(std::string prompt)
{
inputType returnValue;
std::cout << prompt;
std::cin >> returnValue;
while (std::cin.fail()) {
std::cout << "Error! Cannot read input.\n";
std::cin.clear();
std::cin.ignore(INT_MAX,'\n');
std::cout << prompt;
std::cin >> returnValue;
}
return returnValue;
}
template<typename inputType>
inputType ReadValue(std::string prompt, inputType minValue)
{
inputType returnValue=0;
returnValue=ReadValue<inputType>(prompt);
while (returnValue < minValue) {
std::cout << "Error! Value must be >= " << minValue << std::endl;
returnValue=ReadValue<inputType>(prompt);
}
return returnValue;
}
template<typename inputType>
inputType ReadValue(std::string prompt, inputType minValue, inputType maxValue)
{
inputType returnValue=0;
returnValue=ReadValue<inputType>(prompt,minValue);
while (returnValue > maxValue) {
std::cout << "Error! Value must be <= " << maxValue << std::endl;
returnValue=ReadValue<inputType>(prompt,minValue);
}
return returnValue;
}
+165
View File
@@ -0,0 +1,165 @@
#include "list.h"
#include "input.h"
#include <exception>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iterator>
void List::Clear()
{
if (size > 0)
{
delete[] data;
size = 0;
data = nullptr;
}
}
std::string List::Display()
{
std::string result;
if (size > 0)
{
std::cout << "List values:\n";
for (std::string *ptr = data; ptr < data + size; ptr++)
{
result = result + *ptr + " ";
}
}
else
{
result = "List is empty.\n";
}
return result;
}
// There must be a function to allow the list size to be increased without losing data that has been previously stored in the list.
void List::Resize(long numValues)
{
try
{
if (numValues < 1 || numValues > MAX_SIZE)
{
throw "Error! Invalid list size specified.";
}
if (size == 0)
{
Clear();
data = new std::string[numValues];
if (data == nullptr)
{
throw "Error! Could not allocate memory for list.";
}
size = numValues;
}
else
{
temp = new std::string[size + numValues];
copy(data, data + size, temp);
Clear();
data = new std::string[size + numValues];
std::string *tempPtr = temp;
for (std::string *ptr=data; ptr<data+size+numValues; ptr++) {
*ptr= *tempPtr;
}
size = numValues + size;
delete[] temp;
}
}
catch (std::exception &e)
{
throw "Error! Could not allocate memory for list.";
}
}
void List::SetValue(std::string value, long pos)
{
if (pos < 0 || pos >= size)
{
throw "Error! Invalid position in list specified.";
}
data[pos] = value;
}
std::string List::GetValue(long pos)
{
if (pos < 0 || pos >= size)
{
throw "Error! Invalid position in list specified.";
}
return data[pos];
}
void List::Remove(std::string value)
{
int index;
for (int i = 0; i < size; i++)
{
if (data[i] == value)
{
index = i;
}
}
for (int i = index; i < size; i++)
data[i] = data[i + 1];
}
void List::Add()
{
try {
long x=ReadValue<long>("Number of values? ");
Resize(x);
if (size == 0) {
for (std::string *ptr=data; ptr<data+size; ptr++) {
*ptr=ReadValue<std::string>("Value? ");
}
} else {
for (std::string *ptr=data; ptr<data+size+x; ptr++) {
*ptr=ReadValue<std::string>("Value? ");
}
}
}
catch (const char* s) {
throw s;
}
}
std::ostream &operator<<(std::ostream &out, List &l)
{
out << l.Display();
return out;
}
List::List()
{
data = nullptr;
size = 0;
}
List::~List()
{
Clear();
}
List::List(const List &x)
{
size = x.size;
data = new std::string[size];
for (long i = 0; i < x.size; i++)
{
data[i] = x.data[i];
}
}
+36
View File
@@ -0,0 +1,36 @@
#ifndef LIST_H
#define LIST_H
#include <iostream>
class List
{
private:
std::string* temp;
public:
std::string* data;
long size;
enum {MAX_SIZE=1000};
void Remove(std::string value);
void Add();
void Resize(long numValues);
void Clear();
void SetValue(std::string value, long pos);
std::string GetValue(long pos);
long GetSize();
void Input(long newSize);
std::string Display();
List();
List(const List& l);
~List();
};
#endif
std::istream& operator>> (std::istream& in, List& l);
std::ostream& operator<< (std::ostream& out, List& l);
@@ -0,0 +1,72 @@
//
// main.cpp
// BookList
//
// Created by Austin Bennett on 6/22/22.
//
/*
Create a C++ program that will keep a list of books. Your program must meet the following criteria:
ø The program will provide the user with a menu to add names to the list, delete a name from the list (searching by title), display the list in it's entirety
√ The list of books will be stored as a dynamically allocated array of strings. The strings can be either STL strings or C style strings
√ The list must be stored in a class
√ There must be an operator overload created for the stream extraction operator that will handle the output of the list
√ You must provide a copy constructor for the class that will allow the programmer to set one class object equal to another
√ There must be a function to allow the list size to be increased without losing data that has been previously stored in the list.
*/
#include <iostream>
#include "list.h"
#include "input.h"
// The program will provide the user with a menu to add names to the list, delete a name from the list (searching by title), display the list in it's entirety
void menu(List books) {
int choice;
bool inProgram = true;
while (inProgram != false){
std::cout << "*******************************\n";
std::cout << " 1 - Add Item.\n";
std::cout << " 2 - Delete Item.\n";
std::cout << " 3 - Display List.\n";
std::cout << " 4 - Exit.\n";
choice = ReadValue<int>("Enter your choice and press return: ");
switch (choice) {
case 1: // Add Item
books.Add();
break;
case 2: // Delete Item
books.Remove(ReadValue<std::string>("Enter Book to Remove: "));
break;
case 3: // Display List
// There must be an operator overload created for the stream extraction operator that will handle the output of the list
std::cout << books;
break;
case 4:
std::cout << "End of Program.\n";
inProgram = false;
break;
default:
std::cout << "Not a Valid Choice. \n";
std::cout << "Choose again.\n";
std::cin >> choice;
break;
}
}
}
int main(int argc, const char * argv[]) {
// The list must be stored in a class
List books;
menu(books);
// You must provide a copy constructor for the class that will allow the programmer to set one class object equal to another
List books2 = List(books);
return 0;
}
Binary file not shown.
Binary file not shown.
View File
+8
View File
@@ -0,0 +1,8 @@
{
"files.associations": {
"iosfwd": "cpp",
"typeinfo": "cpp",
"vector": "cpp",
"string": "cpp"
}
}
+28
View File
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Binary file not shown.
@@ -0,0 +1,8 @@
{
"files.associations": {
"iosfwd": "cpp",
"typeinfo": "cpp",
"vector": "cpp",
"string": "cpp"
}
}
+28
View File
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
+49
View File
@@ -0,0 +1,49 @@
/*
* Header file for ReadValue
*/
#include <iostream>
#include <climits>
#include <string>
template<typename inputType>
inputType ReadValue(std::string prompt)
{
inputType returnValue=0;
std::cout << prompt;
std::cin >> returnValue;
while (std::cin.fail()) {
std::cout << "Error! Cannot read input.\n";
std::cin.clear();
std::cin.ignore(INT_MAX,'\n');
std::cout << prompt;
std::cin >> returnValue;
}
return returnValue;
}
template<typename inputType>
inputType ReadValue(std::string prompt, inputType minValue)
{
inputType returnValue=0;
returnValue=ReadValue<inputType>(prompt);
while (returnValue < minValue) {
std::cout << "Error! Value must be >= " << minValue << std::endl;
returnValue=ReadValue<inputType>(prompt);
}
return returnValue;
}
template<typename inputType>
inputType ReadValue(std::string prompt, inputType minValue, inputType maxValue)
{
inputType returnValue=0;
returnValue=ReadValue<inputType>(prompt,minValue);
while (returnValue > maxValue) {
std::cout << "Error! Value must be <= " << maxValue << std::endl;
returnValue=ReadValue<inputType>(prompt,minValue);
}
return returnValue;
}
@@ -0,0 +1,40 @@
#include "person.cpp"
using namespace std;
class Laborer : public Person
{
protected:
string _job;
string _laborerEmployeeID;
string _hourlySalary;
string _hoursWorked;
public:
Laborer(string laborerName, string laborerBirthday, string laborerSSN, string job, string employeeID, string hourlySalary, string hoursWorked) : Person(laborerName, laborerBirthday, laborerSSN)
{
_job = job;
_laborerEmployeeID = employeeID;
_hourlySalary = hourlySalary;
_hoursWorked = hoursWorked;
}
// Accessors
string getJob() { return _job; };
string getEmployeeID() { return _laborerEmployeeID; };
string getHourlySalary() { return _hourlySalary; };
string getHoursWorked() { return _hoursWorked; };
string getType() { return "Laborer"; }
// Mutators
void setJob(string job) { _job = job; };
void setEmployeeID(string employeeID) { _laborerEmployeeID = employeeID; };
void setHourlySalary(string hourlySalary) { _hourlySalary = hourlySalary; };
void setHoursWorked(string hoursWorked) { _hoursWorked = hoursWorked; };
void Display() {
cout << endl;
cout << getType() << ":" << endl;
cout << " " << getName() << " " << getBirthday() << " " << getSSN() << " " << getJob() << " " << getEmployeeID() << " " << getHourlySalary() << " " << getHoursWorked() << endl;
}
};
+150
View File
@@ -0,0 +1,150 @@
//
// main.cpp
// Business
//
// Created by Austin Bennett on 7/7/22.
//
#include <iostream>
#include <vector>
#include "input.h"
#include "person.cpp"
#include "laborer.cpp"
#include "manager.cpp"
#include "owner.cpp"
using namespace std;
int main()
{
vector<Person *> list;
int choice;
do
{
cout << endl
<< " 1 - Add Laborer\n"
<< " 2 - Add Manager\n"
<< " 3 - Add Owner\n"
<< " 4 - Display List\n"
<< " 5 - Exit.\n"
<< " Enter your choice and press return: ";
cin >> choice;
cout << endl;
switch (choice)
{
case 1: // Add Laborer
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Job: ";
string job;
getline(cin, job);
cout << "Employee ID: ";
string laborerEmployeeID;
getline(cin, laborerEmployeeID);
cout << "Hourly Salary: ";
string hourlySalary;
getline(cin, hourlySalary);
cout << "Hours Worked: ";
string hoursWorked;
getline(cin, hoursWorked);
list.push_back(new Laborer(name, birthday, ssn, job, laborerEmployeeID, hourlySalary, hoursWorked));
break;
}
case 2: // Add Manager
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Department: ";
string department;
getline(cin, department);
cout << "Employee ID: ";
string managerEmployeeID;
getline(cin, managerEmployeeID);
cout << "Salary: ";
string salary;
getline(cin, salary);
list.push_back(new Manager(name, birthday, ssn, department, managerEmployeeID, salary));
break;
}
case 3: // Add Owner
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Percent Owned: ";
string percentOwned;
getline(cin, percentOwned);
cout << "Owner Since: ";
string ownerSince;
getline(cin, ownerSince);
list.push_back(new Owner(name, birthday, ssn, percentOwned, ownerSince));
break;
}
case 4: // Display List
for (int i = 0; i < list.size(); i++)
{
list[i]->Display();
}
break;
case 5: // Exit
cout << "End of Program.\n";
break;
default:
cout << "Not a Valid Choice. \n"
<< "Choose again.\n";
break;
}
} while (choice != 5);
return 0;
}
@@ -0,0 +1,36 @@
#include "person.cpp"
using namespace std;
class Manager : public Person
{
protected:
string _department;
string _managerEmployeeID;
string _salary;
public:
Manager(string managerName, string managerBirthday, string managerSSN, string department, string employeeID, string salary) : Person(managerName, managerBirthday, managerSSN)
{
_department = department;
_managerEmployeeID = employeeID;
_salary = salary;
}
// Accessors
string getDepartment() { return _department; };
string getEmployeeID() { return _managerEmployeeID; };
string getSalary() { return _salary; };
string getType() { return "Manager"; };
// Mutators
void setDepartment(string department) { _department = department; };
void setEmployeeID(string employeeID) { _managerEmployeeID = employeeID; };
void setSalary(string salary) { _salary = salary; };
void Display() {
cout << endl;
cout << getType() << ":" << endl;
cout << " " << getName() << " " << getBirthday() << " " << getSSN() << " " << getDepartment() << " " << getEmployeeID() << " " << getSalary() << endl;
}
};
@@ -0,0 +1,32 @@
#include "person.cpp"
using namespace std;
class Owner : public Person
{
protected:
string _percentOwned;
string _ownerSince;
public:
Owner(string ownerName, string ownerBirthday, string ownerSSN, string percentOwned, string ownerSince) : Person(ownerName, ownerBirthday, ownerSSN)
{
_percentOwned = percentOwned;
_ownerSince = ownerSince;
}
// Accessors
string getPercentOwned() { return _percentOwned; };
string getOwnerSince() { return _ownerSince; };
string getType() { return "Owner"; };
// Mutators
void setPercentOwned(string percentOwned) { _percentOwned = percentOwned; };
void setOwnerSince(string ownerSince) { _ownerSince = ownerSince; };
void Display() {
cout << endl;
cout << getType() << ":" << endl;
cout << " " << getName() << " " << getBirthday() << " " << getSSN() << " " << getPercentOwned() << " " << getOwnerSince()<< endl;
}
};
@@ -0,0 +1,35 @@
#include <string>
#include <iostream>
#pragma once
using namespace std;
class Person
{
protected:
string _name;
string _birthday;
string _ssn;
public:
Person(string name, string birthday, string ssn)
{
_name = name;
_birthday = birthday;
_ssn = ssn;
}
// Accessors
string getName() { return _name; };
string getBirthday() { return _birthday; };
string getSSN() { return _ssn; };
string getType() { return "Person"; };
// Mutators
void setName(string name) { _name = name; }
void setBirthday(string birthday) { _birthday = birthday; };
void setSSN(string ssn) { _ssn = ssn; };
virtual void Display() = 0;
};
Binary file not shown.
+49
View File
@@ -0,0 +1,49 @@
/*
* Header file for ReadValue
*/
#include <iostream>
#include <climits>
#include <string>
template<typename inputType>
inputType ReadValue(std::string prompt)
{
inputType returnValue=0;
std::cout << prompt;
std::cin >> returnValue;
while (std::cin.fail()) {
std::cout << "Error! Cannot read input.\n";
std::cin.clear();
std::cin.ignore(INT_MAX,'\n');
std::cout << prompt;
std::cin >> returnValue;
}
return returnValue;
}
template<typename inputType>
inputType ReadValue(std::string prompt, inputType minValue)
{
inputType returnValue=0;
returnValue=ReadValue<inputType>(prompt);
while (returnValue < minValue) {
std::cout << "Error! Value must be >= " << minValue << std::endl;
returnValue=ReadValue<inputType>(prompt);
}
return returnValue;
}
template<typename inputType>
inputType ReadValue(std::string prompt, inputType minValue, inputType maxValue)
{
inputType returnValue=0;
returnValue=ReadValue<inputType>(prompt,minValue);
while (returnValue > maxValue) {
std::cout << "Error! Value must be <= " << maxValue << std::endl;
returnValue=ReadValue<inputType>(prompt,minValue);
}
return returnValue;
}
+40
View File
@@ -0,0 +1,40 @@
#include "person.cpp"
using namespace std;
class Laborer : public Person
{
protected:
string _job;
string _laborerEmployeeID;
string _hourlySalary;
string _hoursWorked;
public:
Laborer(string laborerName, string laborerBirthday, string laborerSSN, string job, string employeeID, string hourlySalary, string hoursWorked) : Person(laborerName, laborerBirthday, laborerSSN)
{
_job = job;
_laborerEmployeeID = employeeID;
_hourlySalary = hourlySalary;
_hoursWorked = hoursWorked;
}
// Accessors
string getJob() { return _job; };
string getEmployeeID() { return _laborerEmployeeID; };
string getHourlySalary() { return _hourlySalary; };
string getHoursWorked() { return _hoursWorked; };
string getType() { return "Laborer"; }
// Mutators
void setJob(string job) { _job = job; };
void setEmployeeID(string employeeID) { _laborerEmployeeID = employeeID; };
void setHourlySalary(string hourlySalary) { _hourlySalary = hourlySalary; };
void setHoursWorked(string hoursWorked) { _hoursWorked = hoursWorked; };
void Display() {
cout << endl;
cout << getType() << ":" << endl;
cout << " " << getName() << " " << getBirthday() << " " << getSSN() << " " << getJob() << " " << getEmployeeID() << " " << getHourlySalary() << " " << getHoursWorked() << endl;
}
};
+233
View File
@@ -0,0 +1,233 @@
//
// main.cpp
// Business
//
// Created by Austin Bennett on 7/7/22.
//
#include <iostream>
#include <vector>
#include "person.cpp"
#include "laborer.cpp"
#include "manager.cpp"
#include "owner.cpp"
using namespace std;
vector<Person *> list;
void DisplayAddMenu()
{
int choice;
do
{
cout << endl
<< " 1 - Add Laborer\n"
<< " 2 - Add Manager\n"
<< " 3 - Add Owner\n"
<< " 4 - Exit.\n"
<< " Enter your choice and press return: ";
cin >> choice;
cout << endl;
if (choice == 1)
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Job: ";
string job;
getline(cin, job);
cout << "Employee ID: ";
string laborerEmployeeID;
getline(cin, laborerEmployeeID);
cout << "Hourly Salary: ";
string hourlySalary;
getline(cin, hourlySalary);
cout << "Hours Worked: ";
string hoursWorked;
getline(cin, hoursWorked);
list.push_back(new Laborer(name, birthday, ssn, job, laborerEmployeeID, hourlySalary, hoursWorked));
}
else if (choice == 2)
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Department: ";
string department;
getline(cin, department);
cout << "Employee ID: ";
string managerEmployeeID;
getline(cin, managerEmployeeID);
cout << "Salary: ";
string salary;
getline(cin, salary);
list.push_back(new Manager(name, birthday, ssn, department, managerEmployeeID, salary));
}
else if (choice == 3)
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Percent Owned: ";
string percentOwned;
getline(cin, percentOwned);
cout << "Owner Since: ";
string ownerSince;
getline(cin, ownerSince);
list.push_back(new Owner(name, birthday, ssn, percentOwned, ownerSince));
}
else if (choice == 4)
{
break;
}
else
{
cout << "Invalid Input\n";
cin.clear();
cin.ignore(10000, '\n');
}
} while (choice != 4);
}
void DisplayListMenu()
{
int choice;
do
{
cout << endl
<< " 1 - View Laborers\n"
<< " 2 - View Managers\n"
<< " 3 - View Owners\n"
<< " 4 - Exit.\n"
<< " Enter your choice and press return: ";
cin >> choice;
cout << endl;
if (choice == 1)
{
for (int i = 0; i < list.size(); i++)
{
Person* person = list[i];
cout << person -> getType();;
string type = list[i]->getType();
if (type == "Laborer")
{
list[i]->Display();
}
}
}
else if (choice == 2)
{
for (int i = 0; i < list.size(); i++)
{
Person *person = list[i];
string type = person->getType();
if (type == "Manager")
{
list[i]->Display();
}
}
}
if (choice == 3)
{
for (int i = 0; i < list.size(); i++)
{
string type = list[i]->getType();
if (type == "Owner")
{
list[i]->Display();
}
}
}
else if (choice == 4)
{
break;
}
else
{
cin.clear();
cin.ignore(10000, '\n');
}
} while (choice != 4);
}
int main()
{
int choice;
do
{
cout << endl
<< " 1 - Add Person\n"
<< " 2 - Display List\n"
<< " 3 - Exit.\n"
<< " Enter your choice and press return: ";
cin >> choice;
cout << endl;
if (choice == 1)
{
DisplayAddMenu();
}
else if (choice == 2)
{
DisplayListMenu();
}
else if (choice == 3)
{
cout << "End of Program.\n";
cin.clear();
cin.ignore(10000, '\n');
}
else
{
cout << "Not a Valid Choice. \nChoose again.\n";
}
} while (choice != 3);
return 0;
}
+36
View File
@@ -0,0 +1,36 @@
#include "person.cpp"
using namespace std;
class Manager : public Person
{
protected:
string _department;
string _managerEmployeeID;
string _salary;
public:
Manager(string managerName, string managerBirthday, string managerSSN, string department, string employeeID, string salary) : Person(managerName, managerBirthday, managerSSN)
{
_department = department;
_managerEmployeeID = employeeID;
_salary = salary;
}
// Accessors
string getDepartment() { return _department; };
string getEmployeeID() { return _managerEmployeeID; };
string getSalary() { return _salary; };
string getType() { return "Manager"; };
// Mutators
void setDepartment(string department) { _department = department; };
void setEmployeeID(string employeeID) { _managerEmployeeID = employeeID; };
void setSalary(string salary) { _salary = salary; };
void Display() {
cout << endl;
cout << getType() << ":" << endl;
cout << " " << getName() << " " << getBirthday() << " " << getSSN() << " " << getDepartment() << " " << getEmployeeID() << " " << getSalary() << endl;
}
};
+32
View File
@@ -0,0 +1,32 @@
#include "person.cpp"
using namespace std;
class Owner : public Person
{
protected:
string _percentOwned;
string _ownerSince;
public:
Owner(string ownerName, string ownerBirthday, string ownerSSN, string percentOwned, string ownerSince) : Person(ownerName, ownerBirthday, ownerSSN)
{
_percentOwned = percentOwned;
_ownerSince = ownerSince;
}
// Accessors
string getPercentOwned() { return _percentOwned; };
string getOwnerSince() { return _ownerSince; };
string getType() { return "Owner"; };
// Mutators
void setPercentOwned(string percentOwned) { _percentOwned = percentOwned; };
void setOwnerSince(string ownerSince) { _ownerSince = ownerSince; };
void Display() {
cout << endl;
cout << getType() << ":" << endl;
cout << " " << getName() << " " << getBirthday() << " " << getSSN() << " " << getPercentOwned() << " " << getOwnerSince()<< endl;
}
};
+36
View File
@@ -0,0 +1,36 @@
#include <string>
#include <iostream>
#pragma once
using namespace std;
class Person
{
protected:
string _name;
string _birthday;
string _ssn;
public:
Person(string name, string birthday, string ssn)
{
_name = name;
_birthday = birthday;
_ssn = ssn;
}
// Accessors
string getName() { return _name; };
string getBirthday() { return _birthday; };
string getSSN() { return _ssn; };
// Mutators
void setName(string name) { _name = name; }
void setBirthday(string birthday) { _birthday = birthday; };
void setSSN(string ssn) { _ssn = ssn; };
virtual void Display() = 0;
virtual string getType();
};
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 507 KiB

@@ -0,0 +1,98 @@
//
// doublylinkedlist.cpp
// DoublyLinkedList
//
// Created by Austin Bennett on 7/18/22.
//
/*
Constructor
Destructor
Insert function
Remove function
Accessor function
Mutator function
*/
#include <iostream>
#include "doublylinkedlist.hpp"
using namespace::std;
DoublyLinkedList::DoublyLinkedList() {
front = NULL;
back = NULL;
}
void DoublyLinkedList::Insert(double data) {
Node* newNode = new Node(data);
bool isEmpty = (front == NULL);
if (isEmpty) {
front = newNode;
back = newNode;
newNode -> prev = NULL;
newNode -> next = NULL;
} else {
back -> next = newNode;
newNode -> prev = back;
newNode -> next = NULL;
back = newNode;
}
}
void DoublyLinkedList::Remove(int index) {
Node* temp = front;
int count = 0;
for (int i = 0; temp != NULL && i < index; i++) {
temp = temp -> next;
}
if (temp == front) {
temp -> next = front;
front -> prev = NULL;
} else if (temp == back) {
temp -> prev = back;
back -> next = NULL;
} else {
Node* a = temp -> prev;
Node* b = temp -> next;
b -> prev = a;
a -> next = b;
}
free(temp);
return;
}
void DoublyLinkedList::DisplayFB() {
Node* temp = front;
while (temp != NULL) {
cout << temp -> data << " -> ";
temp = temp -> next;
}
cout << "NULL" << endl;
}
void DoublyLinkedList::DisplayBF() {
Node* temp = back;
while (temp != NULL) {
cout << temp -> data << " -> ";
temp = temp -> prev;
}
cout << "NULL" << endl;
}
void DoublyLinkedList::Mutate(int index, double value) {
Node* temp = front;
for (int i = 0; temp != NULL && i < index; i++) {
temp = temp->next;
}
temp -> data = value;
}
@@ -0,0 +1,37 @@
//
// doublylinkedlist.hpp
// DoublyLinkedList
//
// Created by Austin Bennett on 7/18/22.
//
/*
Constructor
Destructor
Insert function
Remove function
Accessor function
Mutator function
*/
#ifndef doublylinkedlist_hpp
#define doublylinkedlist_hpp
#include <stdio.h>
#include "node.hpp"
class DoublyLinkedList {
private:
Node* front;
Node* back;
public:
DoublyLinkedList();
//~DoublyLinkedList();
void Insert(double data);
void Remove(int index);
void DisplayFB();
void DisplayBF();
void Mutate(int index, double value);
};
#endif /* doublylinkedlist_hpp */
@@ -0,0 +1,49 @@
/*
* Header file for ReadValue
*/
#include <iostream>
#include <climits>
#include <string>
template<typename inputType>
inputType ReadValue(std::string prompt)
{
inputType returnValue=0;
std::cout << prompt;
std::cin >> returnValue;
while (std::cin.fail()) {
std::cout << "Error! Cannot read input.\n";
std::cin.clear();
std::cin.ignore(INT_MAX,'\n');
std::cout << prompt;
std::cin >> returnValue;
}
return returnValue;
}
template<typename inputType>
inputType ReadValue(std::string prompt, inputType minValue)
{
inputType returnValue=0;
returnValue=ReadValue<inputType>(prompt);
while (returnValue < minValue) {
std::cout << "Error! Value must be >= " << minValue << std::endl;
returnValue=ReadValue<inputType>(prompt);
}
return returnValue;
}
template<typename inputType>
inputType ReadValue(std::string prompt, inputType minValue, inputType maxValue)
{
inputType returnValue=0;
returnValue=ReadValue<inputType>(prompt,minValue);
while (returnValue > maxValue) {
std::cout << "Error! Value must be <= " << maxValue << std::endl;
returnValue=ReadValue<inputType>(prompt,minValue);
}
return returnValue;
}
@@ -0,0 +1,44 @@
#include <iostream>
#include "doublylinkedlist.hpp"
#include "input.h"
using namespace std;
int main()
{
DoublyLinkedList dll = DoublyLinkedList();
cout << "1. Add Value" << endl;
cout << "2. Delete Value" << endl;
cout << "3. Display List (forward)" << endl;
cout << "4. Display List (backward)" << endl;
cout << "5. Quit" << endl;
int choice = ReadValue<int>("Enter Your Choice: ");
do {
if (choice == 1) {
dll.Insert(ReadValue<double>("Enter Your Data: "));
} else if (choice == 2) {
dll.Remove(ReadValue<int>("Enter The Index: "));
} else if (choice == 3) {
dll.DisplayFB();
} else if (choice == 4) {
dll.DisplayBF();
} else if (choice == 5) {
break;
} else {
cout << "Try Again" << endl;
}
// cout << "1. Add Value" << endl;
// cout << "2. Delete Value" << endl;
// cout << "3. Display List (forward)" << endl;
// cout << "4. Display List (backward)" << endl;
// cout << "5. Quit" << endl;
choice = ReadValue<int>("Enter Your Choice: ");
} while (choice != 5);
return 0;
}
@@ -0,0 +1,16 @@
//
// node.cpp
// DoublyLinkedList
//
// Created by Austin Bennett on 7/18/22.
//
#include "node.hpp"
Node::Node(double value) {
data = value;
}
Node::~Node() {
delete this;
}
@@ -0,0 +1,22 @@
//
// node.hpp
// DoublyLinkedList
//
// Created by Austin Bennett on 7/18/22.
//
#ifndef node_hpp
#define node_hpp
#include <stdio.h>
struct Node {
public:
double data;
struct Node *prev;
struct Node *next;
Node(double value);
~Node();
};
#endif /* node_hpp */
Binary file not shown.

After

Width:  |  Height:  |  Size: 507 KiB

@@ -0,0 +1,98 @@
//
// doublylinkedlist.cpp
// DoublyLinkedList
//
// Created by Austin Bennett on 7/18/22.
//
/*
Constructor
Destructor
Insert function
Remove function
Accessor function
Mutator function
*/
#include <iostream>
#include "doublylinkedlist.hpp"
using namespace::std;
DoublyLinkedList::DoublyLinkedList() {
front = NULL;
back = NULL;
}
void DoublyLinkedList::Insert(double data) {
Node* newNode = new Node(data);
bool isEmpty = (front == NULL);
if (isEmpty) {
front = newNode;
back = newNode;
newNode -> prev = NULL;
newNode -> next = NULL;
} else {
back -> next = newNode;
newNode -> prev = back;
newNode -> next = NULL;
back = newNode;
}
}
void DoublyLinkedList::Remove(int index) {
Node* temp = front;
int count = 0;
for (int i = 0; temp != NULL && i < index; i++) {
temp = temp -> next;
}
if (temp == front) {
temp -> next = front;
front -> prev = NULL;
} else if (temp == back) {
temp -> prev = back;
back -> next = NULL;
} else {
Node* a = temp -> prev;
Node* b = temp -> next;
b -> prev = a;
a -> next = b;
}
free(temp);
return;
}
void DoublyLinkedList::DisplayFB() {
Node* temp = front;
while (temp != NULL) {
cout << temp -> data << " -> ";
temp = temp -> next;
}
cout << "NULL" << endl;
}
void DoublyLinkedList::DisplayBF() {
Node* temp = back;
while (temp != NULL) {
cout << temp -> data << " -> ";
temp = temp -> prev;
}
cout << "NULL" << endl;
}
void DoublyLinkedList::Mutate(int index, double value) {
Node* temp = front;
for (int i = 0; temp != NULL && i < index; i++) {
temp = temp->next;
}
temp -> data = value;
}
@@ -0,0 +1,37 @@
//
// doublylinkedlist.hpp
// DoublyLinkedList
//
// Created by Austin Bennett on 7/18/22.
//
/*
Constructor
Destructor
Insert function
Remove function
Accessor function
Mutator function
*/
#ifndef doublylinkedlist_hpp
#define doublylinkedlist_hpp
#include <stdio.h>
#include "node.hpp"
class DoublyLinkedList {
private:
Node* front;
Node* back;
public:
DoublyLinkedList();
//~DoublyLinkedList();
void Insert(double data);
void Remove(int index);
void DisplayFB();
void DisplayBF();
void Mutate(int index, double value);
};
#endif /* doublylinkedlist_hpp */
@@ -0,0 +1,49 @@
/*
* Header file for ReadValue
*/
#include <iostream>
#include <climits>
#include <string>
template<typename inputType>
inputType ReadValue(std::string prompt)
{
inputType returnValue=0;
std::cout << prompt;
std::cin >> returnValue;
while (std::cin.fail()) {
std::cout << "Error! Cannot read input.\n";
std::cin.clear();
std::cin.ignore(INT_MAX,'\n');
std::cout << prompt;
std::cin >> returnValue;
}
return returnValue;
}
template<typename inputType>
inputType ReadValue(std::string prompt, inputType minValue)
{
inputType returnValue=0;
returnValue=ReadValue<inputType>(prompt);
while (returnValue < minValue) {
std::cout << "Error! Value must be >= " << minValue << std::endl;
returnValue=ReadValue<inputType>(prompt);
}
return returnValue;
}
template<typename inputType>
inputType ReadValue(std::string prompt, inputType minValue, inputType maxValue)
{
inputType returnValue=0;
returnValue=ReadValue<inputType>(prompt,minValue);
while (returnValue > maxValue) {
std::cout << "Error! Value must be <= " << maxValue << std::endl;
returnValue=ReadValue<inputType>(prompt,minValue);
}
return returnValue;
}
@@ -0,0 +1,44 @@
#include <iostream>
#include "doublylinkedlist.hpp"
#include "input.h"
using namespace std;
int main()
{
DoublyLinkedList dll = DoublyLinkedList();
cout << "1. Add Value" << endl;
cout << "2. Delete Value" << endl;
cout << "3. Display List (forward)" << endl;
cout << "4. Display List (backward)" << endl;
cout << "5. Quit" << endl;
int choice = ReadValue<int>("Enter Your Choice: ");
do {
if (choice == 1) {
dll.Insert(ReadValue<double>("Enter Your Data: "));
} else if (choice == 2) {
dll.Remove(ReadValue<int>("Enter The Index: "));
} else if (choice == 3) {
dll.DisplayFB();
} else if (choice == 4) {
dll.DisplayBF();
} else if (choice == 5) {
break;
} else {
cout << "Try Again" << endl;
}
// cout << "1. Add Value" << endl;
// cout << "2. Delete Value" << endl;
// cout << "3. Display List (forward)" << endl;
// cout << "4. Display List (backward)" << endl;
// cout << "5. Quit" << endl;
choice = ReadValue<int>("Enter Your Choice: ");
} while (choice != 5);
return 0;
}
@@ -0,0 +1,16 @@
//
// node.cpp
// DoublyLinkedList
//
// Created by Austin Bennett on 7/18/22.
//
#include "node.hpp"
Node::Node(double value) {
data = value;
}
Node::~Node() {
delete this;
}
@@ -0,0 +1,22 @@
//
// node.hpp
// DoublyLinkedList
//
// Created by Austin Bennett on 7/18/22.
//
#ifndef node_hpp
#define node_hpp
#include <stdio.h>
struct Node {
public:
double data;
struct Node *prev;
struct Node *next;
Node(double value);
~Node();
};
#endif /* node_hpp */
Binary file not shown.
+28
View File
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
@@ -0,0 +1,42 @@
#include "person.cpp"
using namespace std;
class Laborer : public Person
{
protected:
string _job;
string _laborerEmployeeID;
string _hourlySalary;
string _hoursWorked;
public:
Laborer(string laborerName, string laborerBirthday, string laborerSSN, string job, string employeeID, string hourlySalary, string hoursWorked) : Person(laborerName, laborerBirthday, laborerSSN)
{
_job = job;
_laborerEmployeeID = employeeID;
_hourlySalary = hourlySalary;
_hoursWorked = hoursWorked;
}
// Accessors
string getJob() { return _job; };
string getEmployeeID() { return _laborerEmployeeID; };
string getHourlySalary() { return _hourlySalary; };
string getHoursWorked() { return _hoursWorked; };
string getType() { return "Laborer"; }
virtual string getName() { return _name; };
// Mutators
void setJob(string job) { _job = job; };
void setEmployeeID(string employeeID) { _laborerEmployeeID = employeeID; };
void setHourlySalary(string hourlySalary) { _hourlySalary = hourlySalary; };
void setHoursWorked(string hoursWorked) { _hoursWorked = hoursWorked; };
void Display()
{
cout << endl;
cout << getType() << ":" << endl;
cout << " " << getName() << " " << getBirthday() << " " << getSSN() << " " << getJob() << " " << getEmployeeID() << " " << getHourlySalary() << " " << getHoursWorked() << endl;
}
};
@@ -0,0 +1,251 @@
//
// main.cpp
// Business
//
// Created by Austin Bennett on 7/7/22.
//
#include <iostream>
#include <vector>
#include "person.cpp"
#include "laborer.cpp"
#include "manager.cpp"
#include "owner.cpp"
using namespace std;
vector<Person *> list;
void DisplayAddMenu()
{
int choice;
do
{
cout << endl
<< " 1 - Add Laborer\n"
<< " 2 - Add Manager\n"
<< " 3 - Add Owner\n"
<< " 4 - Return to Main Menu\n"
<< " Enter your choice and press return: ";
cin >> choice;
cout << endl;
if (choice == 1)
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Job: ";
string job;
getline(cin, job);
cout << "Employee ID: ";
string laborerEmployeeID;
getline(cin, laborerEmployeeID);
cout << "Hourly Salary: ";
string hourlySalary;
getline(cin, hourlySalary);
cout << "Hours Worked: ";
string hoursWorked;
getline(cin, hoursWorked);
list.push_back(new Laborer(name, birthday, ssn, job, laborerEmployeeID, hourlySalary, hoursWorked));
}
else if (choice == 2)
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Department: ";
string department;
getline(cin, department);
cout << "Employee ID: ";
string managerEmployeeID;
getline(cin, managerEmployeeID);
cout << "Salary: ";
string salary;
getline(cin, salary);
list.push_back(new Manager(name, birthday, ssn, department, managerEmployeeID, salary));
}
else if (choice == 3)
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Percent Owned: ";
string percentOwned;
getline(cin, percentOwned);
cout << "Owner Since: ";
string ownerSince;
getline(cin, ownerSince);
list.push_back(new Owner(name, birthday, ssn, percentOwned, ownerSince));
}
else if (choice == 4)
{
break;
}
else
{
cout << "Invalid Input\n";
cin.clear();
cin.ignore(10000, '\n');
}
} while (choice != 4);
}
void DisplayListMenu()
{
int choice;
do
{
cout << endl
<< " 1 - View Laborers\n"
<< " 2 - View Managers\n"
<< " 3 - View Owners\n"
<< " 4 - Return to Main Menu\n"
<< " Enter your choice and press return: ";
cin >> choice;
cout << endl;
if (choice == 1)
{
for (int i = 0; i < list.size(); i++)
{
string type = list[i]->getType();
if (type == "Laborer")
{
list[i]->Display();
}
}
}
else if (choice == 2)
{
for (int i = 0; i < list.size(); i++)
{
string type = list[i]->getType();
if (type == "Manager")
{
list[i]->Display();
}
}
}
if (choice == 3)
{
for (int i = 0; i < list.size(); i++)
{
string type = list[i]->getType();
if (type == "Owner")
{
list[i]->Display();
}
}
}
else if (choice == 4)
{
break;
}
else
{
cin.clear();
cin.ignore(10000, '\n');
}
} while (choice != 4);
}
int main()
{
int choice;
do
{
cout << endl
<< " 1 - Add Person\n"
<< " 2 - Display List\n"
<< " 3 - Sort List\n"
<< " 4 - Exit.\n"
<< " Enter your choice and press return: ";
cin >> choice;
cout << endl;
if (choice == 1)
{
DisplayAddMenu();
}
else if (choice == 2)
{
DisplayListMenu();
}
else if (choice == 3)
{
int i, j, n;
n = list.size();
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < n - i - 1; j++)
{
if (list[j]->getName() > list[j + 1]->getName())
{
swap(list[j], list[j + 1]);
}
}
}
for (int i = 0; i < n; i++)
{
list[i]->Display();
}
}
else if (choice == 4)
{
cout << "End of Program.\n";
cin.clear();
cin.ignore(10000, '\n');
}
else
{
cout << "Not a Valid Choice. \nChoose again.\n";
}
} while (choice != 4);
return 0;
}
@@ -0,0 +1,38 @@
#include "person.cpp"
using namespace std;
class Manager : public Person
{
protected:
string _department;
string _managerEmployeeID;
string _salary;
public:
Manager(string managerName, string managerBirthday, string managerSSN, string department, string employeeID, string salary) : Person(managerName, managerBirthday, managerSSN)
{
_department = department;
_managerEmployeeID = employeeID;
_salary = salary;
}
// Accessors
string getDepartment() { return _department; };
string getEmployeeID() { return _managerEmployeeID; };
string getSalary() { return _salary; };
string getType() { return "Manager"; };
virtual string getName() { return _name; };
// Mutators
void setDepartment(string department) { _department = department; };
void setEmployeeID(string employeeID) { _managerEmployeeID = employeeID; };
void setSalary(string salary) { _salary = salary; };
void Display()
{
cout << endl;
cout << getType() << ":" << endl;
cout << " " << getName() << " " << getBirthday() << " " << getSSN() << " " << getDepartment() << " " << getEmployeeID() << " " << getSalary() << endl;
}
};
@@ -0,0 +1,34 @@
#include "person.cpp"
using namespace std;
class Owner : public Person
{
protected:
string _percentOwned;
string _ownerSince;
public:
Owner(string ownerName, string ownerBirthday, string ownerSSN, string percentOwned, string ownerSince) : Person(ownerName, ownerBirthday, ownerSSN)
{
_percentOwned = percentOwned;
_ownerSince = ownerSince;
}
// Accessors
string getPercentOwned() { return _percentOwned; };
string getOwnerSince() { return _ownerSince; };
string getType() { return "Owner"; };
virtual string getName() { return _name; };
// Mutators
void setPercentOwned(string percentOwned) { _percentOwned = percentOwned; };
void setOwnerSince(string ownerSince) { _ownerSince = ownerSince; };
void Display()
{
cout << endl;
cout << getType() << ":" << endl;
cout << " " << getName() << " " << getBirthday() << " " << getSSN() << " " << getPercentOwned() << " " << getOwnerSince() << endl;
}
};
@@ -0,0 +1,36 @@
#include <string>
#include <iostream>
#pragma once
using namespace std;
class Person
{
protected:
string _name;
string _birthday;
string _ssn;
public:
Person(string name, string birthday, string ssn)
{
_name = name;
_birthday = birthday;
_ssn = ssn;
}
// Accessors
string getBirthday() { return _birthday; };
string getSSN() { return _ssn; };
// Mutators
void setName(string name) { _name = name; }
void setBirthday(string birthday) { _birthday = birthday; };
void setSSN(string ssn) { _ssn = ssn; };
virtual void Display() = 0;
virtual string getType() = 0;
virtual string getName() = 0;
};
+251
View File
@@ -0,0 +1,251 @@
//
// main.cpp
// Business
//
// Created by Austin Bennett on 7/7/22.
//
#include <iostream>
#include <vector>
#include "person.cpp"
#include "laborer.cpp"
#include "manager.cpp"
#include "owner.cpp"
using namespace std;
vector<Person *> list;
void DisplayAddMenu()
{
int choice;
do
{
cout << endl
<< " 1 - Add Laborer\n"
<< " 2 - Add Manager\n"
<< " 3 - Add Owner\n"
<< " 4 - Return to Main Menu\n"
<< " Enter your choice and press return: ";
cin >> choice;
cout << endl;
if (choice == 1)
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Job: ";
string job;
getline(cin, job);
cout << "Employee ID: ";
string laborerEmployeeID;
getline(cin, laborerEmployeeID);
cout << "Hourly Salary: ";
string hourlySalary;
getline(cin, hourlySalary);
cout << "Hours Worked: ";
string hoursWorked;
getline(cin, hoursWorked);
list.push_back(new Laborer(name, birthday, ssn, job, laborerEmployeeID, hourlySalary, hoursWorked));
}
else if (choice == 2)
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Department: ";
string department;
getline(cin, department);
cout << "Employee ID: ";
string managerEmployeeID;
getline(cin, managerEmployeeID);
cout << "Salary: ";
string salary;
getline(cin, salary);
list.push_back(new Manager(name, birthday, ssn, department, managerEmployeeID, salary));
}
else if (choice == 3)
{
cout << "Name: ";
string name;
cin.ignore();
getline(cin, name);
cout << "Birthday: ";
string birthday;
getline(cin, birthday);
cout << "SSN: ";
string ssn;
getline(cin, ssn);
cout << "Percent Owned: ";
string percentOwned;
getline(cin, percentOwned);
cout << "Owner Since: ";
string ownerSince;
getline(cin, ownerSince);
list.push_back(new Owner(name, birthday, ssn, percentOwned, ownerSince));
}
else if (choice == 4)
{
break;
}
else
{
cout << "Invalid Input\n";
cin.clear();
cin.ignore(10000, '\n');
}
} while (choice != 4);
}
void DisplayListMenu()
{
int choice;
do
{
cout << endl
<< " 1 - View Laborers\n"
<< " 2 - View Managers\n"
<< " 3 - View Owners\n"
<< " 4 - Return to Main Menu\n"
<< " Enter your choice and press return: ";
cin >> choice;
cout << endl;
if (choice == 1)
{
for (int i = 0; i < list.size(); i++)
{
string type = list[i]->getType();
if (type == "Laborer")
{
list[i]->Display();
}
}
}
else if (choice == 2)
{
for (int i = 0; i < list.size(); i++)
{
string type = list[i]->getType();
if (type == "Manager")
{
list[i]->Display();
}
}
}
if (choice == 3)
{
for (int i = 0; i < list.size(); i++)
{
string type = list[i]->getType();
if (type == "Owner")
{
list[i]->Display();
}
}
}
else if (choice == 4)
{
break;
}
else
{
cin.clear();
cin.ignore(10000, '\n');
}
} while (choice != 4);
}
int main()
{
int choice;
do
{
cout << endl
<< " 1 - Add Person\n"
<< " 2 - Display List\n"
<< " 3 - Sort List\n"
<< " 4 - Exit.\n"
<< " Enter your choice and press return: ";
cin >> choice;
cout << endl;
if (choice == 1)
{
DisplayAddMenu();
}
else if (choice == 2)
{
DisplayListMenu();
}
else if (choice == 3)
{
int i, j, n;
n = list.size();
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < n - i - 1; j++)
{
if (list[j]->getName() > list[j + 1]->getName())
{
swap(list[j], list[j + 1]);
}
}
}
for (int i = 0; i < n; i++)
{
list[i]->Display();
}
}
else if (choice == 4)
{
cout << "End of Program.\n";
cin.clear();
cin.ignore(10000, '\n');
}
else
{
cout << "Not a Valid Choice. \nChoose again.\n";
}
} while (choice != 4);
return 0;
}
+8
View File
@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+2
View File
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ListClass.iml" filepath="$PROJECT_DIR$/.idea/ListClass.iml" />
</modules>
</component>
</project>
Binary file not shown.
@@ -0,0 +1 @@
CMakeLists.txt not found in /Users/austin/Documents/School/Summer 2022/CSC 122/ListClass Select CMakeLists.txt
View File
+46
View File
@@ -0,0 +1,46 @@
#include <iostream>
#include <climits>
#include <string>
template <typename inputType>
inputType ReadValue(std::string prompt)
{
inputType returnValue = 0;
std::cout << prompt;
std::cin >> returnValue;
while (std::cin.fail())
{
std::cout << "Error! Cannot read input.\n";
std::cin.clear();
std::cin.ignore(INT_MAX, '\n');
std::cout << prompt;
std::cin >> returnValue;
}
return returnValue;
}
template <typename inputType>
inputType ReadValue(std::string prompt, inputType minValue)
{
inputType returnValue = 0;
returnValue = ReadValue<inputType>(prompt);
while (returnValue < minValue)
{
std::cout << "Error! Value must be >= " << minValue << std::endl;
returnValue = ReadValue<inputType>(prompt);
}
return returnValue;
}
template <typename inputType>
inputType ReadValue(std::string prompt, inputType minValue, inputType maxValue)
{
inputType returnValue = 0;
returnValue = ReadValue<inputType>(prompt, minValue);
while (returnValue > maxValue)
{
std::cout << "Error! Value must be <= " << maxValue << std::endl;
returnValue = ReadValue<inputType>(prompt, minValue);
}
return returnValue;
}
+49
View File
@@ -0,0 +1,49 @@
//
// main.cpp
// Midterm
//
// Created by Austin Bennett on 7/7/22.
//
/*
Redo question number 3 with these changes. Instead of dynamically allocating an array to store the data, your program will will an STL array. Even numbers will also be copied to an STL array. The input of the data and copying of even numbers will require the program to start at the beginning of the array and walk thorugh the values to the end. This must be done using iterators.
*/
#include <iostream>
#include <array>
#include <iterator>
#include <cmath>
#include "input.h"
using namespace std;
int main() {
array<int, 5> arr;
array<int, 5> evenArr;
array<int, 5>::iterator ptr;
array<int, 5>::iterator evenPtr = evenArr.begin();
for (ptr = arr.begin(); ptr < arr.end(); ptr++) {
*ptr = ReadValue<int>("Value: ");
}
// for (ptr = arr.begin(); ptr < arr.end(); ptr++) {
// cout << *ptr;
// }
for (ptr = arr.begin(); ptr < arr.end(); ptr++) {
if (*ptr % 2 == 0) {
*evenPtr = *ptr;
evenPtr++;
} else {
*evenPtr = NULL;
}
}
for (evenPtr = evenArr.begin(); *evenPtr != NULL; evenPtr++) {
cout << *evenPtr;
}
return 0;
}
+71
View File
@@ -0,0 +1,71 @@
### 1. When passing a C-style string as a parameter to a function - is the parameter passed by reference or default?
```
reference
```
### 2. When allocating the size of a C-style string, assume you want to store the string, "Hello, World!". What is the minimum size of the string you would need to allocate. Show how you would declare the string.
```
The minimum size would be 12 [11 for Hello World! and 1 for the null pointer]
```
```
char s[] = "Hello World!";
OR
char* s = "Hello World!";
```
# 3. TODO
# 4. TODO
### 5. What is the difference between composition and inheritence?
```
Composition is a "has-a" relationship while inheritence is a "is-a". Inheritance BASICALLY is a more strict relationship with composition allows for more flexiblity
```
### 6. What is polymorphism? Be sure to include what role virtual functions play in this and the difference between a virtual and pure virtual funciton. Be sure to include the defintion of an abstract base class.
```
Polymorphism allows the same function or object can act differently in different situations.
```
```
Virtual functions are declared by using the keyword "virtual" and return either int, float, or void. They are able to be "overwritten" to return something else.
```
```
The difference between a virtual function and a pure virtual function is that a pure virtual function is that when the function has no defintion.
```
```
An abstract base class is a class that can represent general concepts which can be used as a base for more concrete classes.
```
### 7. Assume that class B is derived publicly from class A which is abstract. The member functions that are private in class A will be private/protected/public/not directly accessible in class B.
```
not directly accesible in class B
```
### 8. Assume that you have a class that has an integer pointer as a private member. One of the member functions will dynamically allocate memory memory and assign the address to that member. Assume that an object of that class type is instantiated and the funtion called to allocate memory. When the object reaches the end of it's scope - will the memory that has been allocated be released automatically? If not, how would you create a mechanism to accomplish this. Be specific.
```
It will not. So we can use a destructor to get rid of that dynamically allocated memory
```
```
~Class() {
delete var;
}
```
### 9. What purpose does a copy constructor serve? Under what circumstances is it required?
```
a copy constructor is a function that initializes an object using another object of the same class. You what to use it when you want to duplicate an object.
```
# 10. Create a class that will store a list of names. Your class needs to include a function that will return the name that appears first aphabetically, and another function that should return the name that appears last alphabetically. You also need to include a function that will sort the list alphabetically. The class does not need to be case insensitive. The three functions should make use of the algorithms discussed in this class.
+8
View File
@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+2
View File
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/NumericOutput.iml" filepath="$PROJECT_DIR$/.idea/NumericOutput.iml" />
</modules>
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.22)
project(NumericOutput)
set(CMAKE_CXX_STANDARD 14)
add_executable(NumericOutput main.cpp)
@@ -0,0 +1,161 @@
{
"inputs" :
[
{
"path" : "CMakeLists.txt"
},
{
"isGenerated" : true,
"path" : "cmake-build-debug/CMakeFiles/3.22.3/CMakeSystem.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/CMakeSystemSpecificInitialize.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Platform/Darwin-Initialize.cmake"
},
{
"isGenerated" : true,
"path" : "cmake-build-debug/CMakeFiles/3.22.3/CMakeCCompiler.cmake"
},
{
"isGenerated" : true,
"path" : "cmake-build-debug/CMakeFiles/3.22.3/CMakeCXXCompiler.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/CMakeSystemSpecificInformation.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/CMakeGenericSystem.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/CMakeInitializeConfigs.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Platform/Darwin.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Platform/UnixPaths.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/CMakeCInformation.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/CMakeLanguageInformation.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Compiler/AppleClang-C.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Compiler/Clang.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Compiler/CMakeCommonCompilerMacros.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Compiler/GNU.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Compiler/CMakeCommonCompilerMacros.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Platform/Apple-AppleClang-C.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Platform/Apple-Clang-C.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Platform/Apple-Clang.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/CMakeCommonLanguageInclude.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/CMakeCXXInformation.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/CMakeLanguageInformation.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Compiler/AppleClang-CXX.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Compiler/Clang.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Platform/Apple-AppleClang-CXX.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Platform/Apple-Clang-CXX.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/Platform/Apple-Clang.cmake"
},
{
"isCMake" : true,
"isExternal" : true,
"path" : "/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.22/Modules/CMakeCommonLanguageInclude.cmake"
}
],
"kind" : "cmakeFiles",
"paths" :
{
"build" : "/Users/austin/Documents/School/Summer 2022/CSC 122/NumericOutput/cmake-build-debug",
"source" : "/Users/austin/Documents/School/Summer 2022/CSC 122/NumericOutput"
},
"version" :
{
"major" : 1,
"minor" : 0
}
}

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