Project 4

This project is a revamp of project 3 and added a part. I will talk about project 3 first and how it differs from this project. In project 3 I was tasked with creating an Emergency Room triage system. This system had a few quirks. The program would be manually rebooted at 2400 hrs. every […]

This project is a revamp of project 3 and added a part. I will talk about project 3 first and how it differs from this project.

In project 3 I was tasked with creating an Emergency Room triage system. This system had a few quirks. The program would be manually rebooted at 2400 hrs. every night, as well as it could not have the same patient’s name in it. When the staff enters a new patient they enter the first and last name, then the priority, and the time in military time. To store all this data we used an array. We also had to use a class that we created. In the class we could use anything we wanted but it could not contain any loops. The loops had to be done in the main function. Now for the revamp for project 4. For this revamp we had to create a second class and then make it work. In class we wrote the “list class”. Below is the code for the list class:

#include "list.h"
#include <iomanip>
#include <iostream>
using namespace std;

//Default constructor
ListType::ListType(){
   actualSize=0;
}//end method

//Mathod gets the size of the array
int ListType::getLength() const{
   return actualSize;
}//end method

//Method adds to the array
void ListType::insert(ListItemType item){
   if (actualSize<MaxSize){
      list[actualSize]=item;
      actualSize++;
      sort();
   }//end if
}//end method

//Method "removes" an item from the array
void ListType::remove(ListItemType item){
   //find the location of "item"
   int position=search(item);
   if (position != -1){
      //"remove" item
      for(int i=position+1; i<=actualSize; i++){
         list[i-1]=list[i];
      }//ends for loop
    actualSize--;
    }// end if
}//end method

// Method retieves where an index is in the array
ListItemType ListType::retrieve(int index) const{
   return list[index];
}

//Method is used to find an "item"
int ListType::search(ListItemType item) {
   int position=-1;
   int i=0;
   while((position==-1) && (i<actualSize)){
      if(list[i]==item){
         position=i;
      }//end if
   i++;
   }//end While loop
return position;
}// end method


// Method is used to sort the array from greatest to least
void ListType::sort(){
   int i;
   int j;
   ListItemType temp;
   for (i=actualSize; i>1;i--){
      for (j=0;j<(i-1); j++){
         if (list[j] > list[j+1]){
            temp=list[j];
            list[j]=list[j+1];
            list[j+1]=temp;
         }//end if
      }//end for
   }//end for
}//end method

The main program for the patient file had to be revamped to use this class. Here is the code for the main program.

/* 
main.cpp
James Moore
April 1, 2014
Dr. Anewalt
CPSC 220
*****Pt or PT stand for Patient this is medical terminology*****
This program is mock triage program. It allows you to enter a patient, thier priority, and the time
the arrived. It sorts the patients by priority. It will tell you who the next Patient in line is.
It will print the entire list. As well as tell you where a patient is in line. 



*/




#include "patienttype.h"
#include "list.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main () {

//prototypes here
void PrintArray(ListType);
int PrintArrayOne(ListType &);

//variables declared here
ListType newList;
PatientType temp;
string PtName;
string fname;
string lname;
string choice;
int priority;
int hrs;
int min;
int a = 0;
int b = 1;
 
 while (a<b){
  
   cout << "Please select your option from the following menu: " << endl << endl;
   cout << "E: Enter a new patient" << endl;
   cout << "N: Find next patient & remove him/her from the list" << endl;
   cout << "S: Determine the position of a specific patient" << endl;
   cout << "P: Print the list of patients" << endl;
   cout << "Q: Quit" << endl << endl;
   cout << "Enter your choice: ";
   cin >> choice;

   if((choice == "E")||(choice =="e")){
      cout << "Please enter the Patient's first and last name: " << endl;
      cin >> fname >> lname;
      temp.set(fname, lname, priority, hrs, min);
      int result = newList.search(temp);
      if (result != -1){
         cout << "Name Already in the list" << endl;
      }//end if
      else {
         cout << "Please enter the Patient's priority." << endl;
         cin >> priority;
         if ((priority < 0) || (priority > 100)){
            cout << "Priority Error. Must be between 0-100" << endl;
            cin >> priority;
         }//end if
            cout << "Please enter the time (hours minutes)" << endl;
            cin >> hrs >> min;
         if ((hrs < 00) || (hrs >23)){
             cout << " Hours Error. Please enter a valid hours." <<endl;
             cin >> hrs; 
         }// end if
         if ((min < 00)||(min > 59)){
             cout << " Minutes Error. Please enter a valid minute." << endl;
             cin >> min; 
         }// end if
      cout << endl;
      temp.set(lname, fname, priority, hrs, min);
      newList.insert(temp);
      }// end else
   
}// end if
         
   
   if((choice == "N")||(choice == "n")){
     int temp = PrintArrayOne(newList); //Function call to print only one name
   }//end if
   if((choice == "S")||(choice == "s")){
      cout << "Please enter the Patient's first and last name to be searched: " << endl;
      cin >> fname >> lname;
      int result = newList.search(temp);
      if (result == -1){
         cout << "The Patient not found in the list." << endl;
      }//end if
      else {
         cout << "Patient was found at position " << result << endl;
      }// end else
   }//end if
   if((choice == "P")||(choice == "p")){
      PrintArray(newList); // Print Patient List Function call
   }// end if
   if((choice == "Q")||(choice == "q")){
       return 0;
   }// end if
}//end while loop
   return 0;
}// end main

//**This printd the entire array**
void PrintArray(ListType waitingList) {
   cout.setf(ios::left, ios::adjustfield); // this is for the print out
   cout << setw(20) << "Last Name";
   cout << setw(20) << "First Name";
   cout << setw(10) << "Priority";
   cout << setw(5) << "Hr:Min" << endl;
int aSize=waitingList.getLength();
int i;
   for (i = 0; i < aSize; i++) { 
	  PatientType temp = waitingList.retrieve(i);
     temp.PrintPerson();
   }// end for
   cout << endl;  
}// end function


//**This function prints the array only one time**
int PrintArrayOne(ListType &PtList) {
   cout.setf(ios::left, ios::adjustfield); // this is for the print out
   cout << setw(20) << "Last Name";
   cout << setw(20) << "First Name";
   cout << setw(10) << "Priority";
   cout << setw(5)  << "Hr:Min" << endl;
  
int i;
   for (i = 0; i < 1; i++) { 
	  PatientType temp = PtList.retrieve(i);
     temp.PrintPerson();
     PtList.remove(temp);
   }// end for
   cout << endl; 
}// end function

I also used my own PatientType class. That I will not be publishing.

 

Now for the second part. For this part I had to create a make shift web cache. It is basically the same thing as the triage program but this time the user had to enter the URL, MIME, number of bytes, and the date added to the list. Both parts use the same list type minus one small change. For the web cache I added a defending and accenting sort method. I also created my own class for this project as well. Below is the main program for the web cache.

/*
main.cpp

James Moore
April 10, 2014
Dr. Anewalt
CPSC 220

This program's purpose is to act like a web browser by checking the cache.
It will store the website URL, size in bytes, the MIMe type, and the date the file was downloaded.

*/

#include "webpagetype.h"
#include "list.h"
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

main(){
//Prototypes
void PrintList(ListType);

//Variable declarations
ListType List;
WebPageType siteList;
int Bytes;
string MIME;
int month;
int day;
string URL;
string selection;

int a=0;
int b=1;

while (a<b){
   
   cout << "Please enter the letter for one of the following selections: " << endl;
   cout << "     R: Receive a URL" << endl;
   cout << "     U: Sort the current cache based on URL" << endl;
   cout << "     P: Print the current cache" << endl;
   cout << "     Q: Quit" << endl;
   cout << "Selection: ";
   cin >> selection;
   
   if((selection == "Q")||(selection =="q")){
      return 0;
   }
   
   if((selection == "R")||(selection == "r")){
         WebPageType getUrl;
         URL = getUrl.EnterURL();   // enter URLs via the webtype class
         int result = List.search(getUrl);  // check to see if the URL is in the array via list class
         if (result != -1){
            cout << "URL is already in the list." << endl;
         }//end if
         else {
            cout << "Please enter the number bytes:" << endl;
            cin >> Bytes;
            cout << "Please enter the MIME type:" << endl;
            cin >> MIME;
            cout << "Please enter the date (month day)" << endl;
            cin >> month >> day;
               if(month>12){
                  cout << "Not a vaild number of months" << endl;
                  cin >> month;
               }//end if
               if(day > 31){
                  cout << "Not a vaild Number of days" << endl;
                  cin >> day;
               }//end if
            cout << endl;
            getUrl.set(URL, MIME, Bytes, day, month);
            List.insert(getUrl); // puts URLs in the array via list class
         }//end else
   }// end if
   
   if((selection == "U")||(selection == "u")){
      List.accendingSort();// sort the method
   }
   
   if((selection == "P")||(selection == "p")){
      PrintList(List);// print method
   }
   

}//end while

return 0;
}//end main


//This is the print function that calls a listtype and webpagetype method   
void PrintList(ListType waitingList) {
   cout.setf(ios::left, ios::adjustfield); // this is for the print out
   cout << setw(20) << "URL";
   cout << setw(20) << "MIME";
   cout << setw(10) << "Bytes";
   cout << setw(5) << "Month/Day" << endl;
int aSize=waitingList.getLength();
int i;
   for (i = 0; i < aSize; i++) { 
	  WebPageType temp = waitingList.retrieve(i);
     temp.Print();
   }//end for
   cout << endl;  
}// end function

This project was partially hard for me. This is because I had to wrap my head around how to use two different class to make one program work. I have learned a lot during this project. Including writing classes, how to implication of two classes in one main, how to create a makeFile, and how to think abstractly with different classes and make them coherent.