Add the cpp files for Assignment 4.

This commit is contained in:
Charles Descamps 2024-10-29 15:02:43 -07:00
parent 94ac292f32
commit cfcce88ebc
4 changed files with 345 additions and 0 deletions

BIN
assignmentFour/medicalRecords Executable file

Binary file not shown.

View file

@ -0,0 +1,158 @@
/*
Program Name: Medical Records
Process: Design a generalized template class named MedicalRecord - a data
structure for managing patient medical information.
Function Input/Parameters: ???
Function Output/Parameters: ???
Function Output/Returned: ???
Device Input/Device: ???
Device Output/Monitor: ???
Dependencies: ???
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <random>
#include <algorithm>
#include <time.h>
using namespace std;
// class definitions
template <class T>
class MedicalRecord
{
private:
T *arr;
int arraySize;
public:
MedicalRecord()
{
//
arr = NULL;
arraySize = 0;
}
MedicalRecord(int size)
{
//
arr = new T[size];
arraySize = size;
}
MedicalRecord(int size, T newArray[])
{
arraySize = size;
arr = new T[size];
for(int copyIterator = 0; copyIterator < size; copyIterator++)
{
arr[copyIterator] = newArray[copyIterator];
}
}
// MedicalRecord(const MedicalRecord &rec)
// {
// //
// MedicalRecord(rec.arraySize, rec.arr);
// }
~MedicalRecord()
{
// for(int deleteIterator = 0; deleteIterator < arraySize; deleteIterator++)
// {
// delete arr[deleteIterator];
// }
delete arr;
arr = NULL;
arraySize = 0;
}
// accessor methods
int getNumberPatients()
{
return arraySize;
}
T getPatientAt(int pos)
{
if(pos < arraySize)
{
if(pos > arraySize)
{
//
return arr[pos];
}
}
}
// mutator methods
// operator overloads
T &operator[](size_t arrSize)
{
return arr[arrSize];
}
// const T &operator[](size_t arrSize)
// {
// return const arr[arrSize];
// }
};
// function definitions
// main function
int main()
{
bool exitValue = false;
int numRecords = 0;
int currentRecord = 0;
int inputRecord = 0;
// string details
string fullString = "";
string patName = "";
int patAge = 0;
string patDetails = "";
// ask user for number of records
cout << "Please enter number of records: ";
cin >> numRecords;
cin.ignore();
cout << endl;
// create the medical records object
MedicalRecord<string> record(numRecords);
// create the display medical record object.
while (!exitValue || currentRecord != numRecords)
{
// ask the user for the relevant information.
cout << "Please enter patient name: ";
cin >> patName;
cout << endl;
cout << "Please enter patient age: ";
cin >> patAge;
cout << "Please enter patient details: ";
cin >> patDetails;
cout << endl;
// assign fullString to the record[currentRecord].
fullString = patName + " " + to_string(patAge) + " " + patDetails;
record[currentRecord] = fullString;
// ask for index to get data out of array using record[inputIndex]
cout << "Enter index to access record: ";
cin >> inputRecord;
// copy data from record to display, then access data and output using display[currentRecord]
string *tempArray = new string[record.getNumberPatients()];
for(int copyString = 0; copyString < record.getNumberPatients(); copyString++)
{
tempArray[copyString] = record.getPatientAt(copyString);
}
MedicalRecord<string> display(numRecords, tempArray);
// erase the patient details after moving into string.
fullString = "";
patName = "";
patAge = 0;
patDetails = "";
// increment the current record
currentRecord = currentRecord + 1;
// ask user if they want to continue.
// if no, then set the exitValue to true.
}
return 0;
}

BIN
assignmentFour/videogamer Executable file

Binary file not shown.

View file

@ -0,0 +1,187 @@
/*
Program Name: Videogamer
Process: designing a set of classes to represent types of characters that might
be seen in a video game.
Function Input/Parameters: ???
Function Output/Parameters: ???
Function Output/Returned: ???
Device Input/Device: ???
Device Output/Monitor: ???
Dependencies: ???
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <random>
#include <algorithm>
#include <time.h>
using namespace std;
// class definitions
class GameCharacter
{
private:
//
protected:
double characterHealth;
string characterName;
int characterLevel;
public:
GameCharacter()
{
//
characterHealth = 0.0;
characterName = "My Character";
characterLevel = 1;
}
GameCharacter(double health, string name, int level)
{
//
characterHealth = health;
characterName = name;
characterLevel = level;
}
// ~GameCharacter()
// {
// //
// }
// virtual ~GameCharacter() = 0;
virtual ~GameCharacter()
{
return;
// cout << "This not works?" << endl;
}
// accessor functions
double getCharacterHealth()
{
return characterHealth;
}
string getCharacterName()
{
return characterName;
}
int getCharacterLevel()
{
return characterLevel;
}
// mutator functions
void setCharacterHealth(double setHealth)
{
characterHealth = setHealth;
}
void setCharacterName(string setName)
{
characterName = setName;
}
void setCharacterLevel(int setLevel)
{
characterLevel = setLevel;
}
// virtual functions
virtual void performUniqueAttack()
{
// nothing happens?
}
};
class Knight : public GameCharacter
{
private:
string armorType;
public:
Knight() : GameCharacter()
{
armorType = "Leather Armor";
setCharacterName("My Knight Character");
}
Knight(double health, string name, int level, string armor) : GameCharacter(health, name, level)
{
armorType = armor;
}
~Knight()
{
//
// cout << "This works?" << endl;
}
// accessor functions
string getArmorType()
{
return armorType;
}
// mutator functions
void setArmorType(string armor)
{
armorType = armor;
}
// virtual functions
void performUniqueAttack()
{
//
cout << getCharacterName() << " performed Knight Attack wearing " << armorType << "!" << endl;
}
};
class Mage : public GameCharacter
{
private:
double mageMana;
public:
Mage() : GameCharacter()
{
mageMana = 0.0;
setCharacterName("My Mage Character");
}
Mage(double health, string name, int level, double mana) : GameCharacter(health, name, level)
{
mageMana = mana;
}
~Mage()
{
//
// cout << "This works?" << endl;
}
// accessor functions
double getMana()
{
return mageMana;
}
// mutator functions
void setMana(double mana)
{
mageMana = mana;
}
// virtual functions
void performUniqueAttack()
{
//
cout << getCharacterName() << " performed Mage Attack with their " << mageMana << " amount of mana." << endl;
}
};
// function definitions
// main function
int main()
{
int setSize = 4;
GameCharacter *characterSet[setSize];
characterSet[0] = new Knight(100.0, "Meta Knight", 20, "Pallidium Armor");
characterSet[1] = new Mage(50.0, "Rosalina", 5, 300.0);
characterSet[2] = new Knight(100.0, "Eomer", 20, "Chainmail Armor");
characterSet[3] = new Mage(50.0, "Gandalf", 20, 900.0);
for(int characterIterator = 0; characterIterator < setSize; characterIterator++)
{
characterSet[characterIterator]->performUniqueAttack();
}
for(int deleteIterator = 0; deleteIterator < setSize; deleteIterator++)
{
delete characterSet[deleteIterator];
}
return 0;
}