Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have just started your new on-campus job at the front desk of the Swinney re

ID: 3732286 • Letter: Y

Question

You have just started your new on-campus job at the front desk of the Swinney recreation center. Your job is to help students check-out and check-in gym items (towels, basket balls, rackets, bikes, etc). Traditionally, students who work this job record all items that students check out and in manually in two text files (checked out and checked in). At the end of the day, they update a third file (students.txt) that includes information about students and what items are currently checked out (if any). However, you believe that this process is tedious, time consuming and error prone. Therefore, you are thinking to automate this process by writing a C++ program that does all the work for you; because you are a great programmer who took 201L, and you can do it! See the following figure to better understand your program input and output.

T-Mobile 4:51 PM Program 4.pdf 1 of 4 Due: March 18th In onder to eeceive full credit, your program must be coerectly running, implements all required functions data and organized Maximum possible points 60 Assigament karning objectives: You ane sepposed to comoctly define and write ncat code that uses classes, functions, dymasic armays, constructors, destractors and overloaded eperators The assignment problem You have just started your new on-campas job at the front desk of the Swinncy recreation center. Your job is to help students check-out and chock-in gym items (towels, basket balls, rackets, bikes, cic). Traditionally, students who woek this job record all ilems that students check out and in manwally in two test files (checked out and chocked in). At the end of the day, they update a third file (students.tst) that includes information about stadents and wat ilems are curreatly chcckod out (if amy). However, you believe that this process is sedious, time consuming and emoe prone. Therefore, you are thinking to auomale this process by writing a C+ program that does all the work for you because you are a great programmer who took 201L, and you can do it! See the following fgure to better understand your perogram input and output Updated lo Your app Figurel.Ovarview of the assignment's input and output data files Hint: you know that not all stadents hit the gym froquently and, therefore, you realize that not all stadents check gym Rems all the time. At the same time, some students check several ie smultancously (e.g. towel locke and a basketball). This means that you are not sure on how much memory to allocate for this data Thus, you wil wnite a Shudlent class that has a dynamic ray to hoild the items that each Student has checked-out UMKC Due: March 18th Your application will have a Snudent class with the fellewing private data members string for first and last name SOpen With Print

Explanation / Answer

ANSWER:

//main.cpp

#include "Student.h"

using namespace std;

void main()

{

   ifstream in("Students.txt");

   ifstream rin("checkouts.txt");

   ifstream lin("checkins.txt");

   ofstream out("Updated_Students.txt");

   unsigned int studentID;

   string item;

   int totalStudents = 0;

   if (!in)

       cout << "failed to open file.";

   if (!rin)

       cout << "failed to open file.";

   if (!lin)

       cout << "failed to open file.";

   int i = 0;

   const int size = 100;

   Student s1;

   Student* students = new Student[size];

while (in >> s1)

   {

       cout << s1;

   }

   //while (!in.eof())

   {

in >> students[totalStudents];

++totalStudents;

   }

   for (int i = 0; i < totalStudents; i++)

   {

     students[i] = s1;

   }

   in.close();

   while (rin.good())

   {

       rin >> studentID;

       for (int i = 0; i < totalStudents; i++)

       {

           if (students[i].getID() == studentID)

           {

               rin >> item;

               students[i].CheckOut(item);

           }

       }

   }

   while (lin.good())

   {

       lin >> item;

       for (int i = 0; i < totalStudents; i++)

       {

           if (students[i].CheckIn(item))

               break;

       }

   }

   for (int i = 0; i < totalStudents; i++)

       out << students[i];

   delete[] students;

   students = NULL;

   in.close();

   rin.close();

   lin.close();

   out.close();

}

//student.cpp

#include "Student.h"

Student::Student()

{

   idNumb = 0;

   firstName = "";

   lastName = "";

   itemName = "";

   aSize = 0;

   numItems = 0;

   pointy = NULL;

}

void Student::setID(unsigned int nID)

{

   if ((nID > 999) && (nID < 100001))

       idNumb = nID;

   else

       cout << "Invalid ID Number.";

}

void Student::setFirst(string nFirst)

{

   firstName = nFirst;

}

void Student::setLast(string nLast)

{

   lastName = nLast;

}

int Student::CheckoutCount()

{

   return numItems;

}

bool Student::CheckOut(const string& item)

{

   if (HasCheckedOut(item))

       return false;

   if (pointy == NULL && aSize == 0)

   {

       string *newPointy = new string[5];

   }

       string *newPointy = new string[aSize];

   for (int i = 0; i < aSize; i++)

   {

       newPointy[i] = pointy[i];

   }

   if (pointy != NULL && aSize > 0)

       delete[] pointy;

   pointy = newPointy;

   pointy[numItems] = itemName;

   numItems++;

   return true;

}

bool Student::CheckIn(const string& item)

{

   if (!HasCheckedOut(item))

       return false;

   string *newPointy = new string[aSize];

   int nArraySize = 0;

   for (int i = 0; i <aSize; i++)

   {

       if (pointy[i] != item)

       {

           newPointy[nArraySize] = pointy[i];

           nArraySize++;

       }

   }

   delete[] pointy;

   pointy = newPointy;

   numItems--;

}

bool Student::HasCheckedOut(const string& item)

{

   for (int i = 0; i < aSize; i++)

   {

       if (pointy[i] == item)

           return true;

   }

   return false;

}

void Student::Clear()

{

idNumb = 0;

   firstName = "";

   lastName = "";

   if((pointy != NULL) && (numItems > 0))

   delete[] pointy;

   pointy = NULL;

   numItems = 0;

}

Student::~Student()

{

   delete[] pointy;

   pointy = NULL;

}

istream& operator>>(istream& in, Student& item)

{

   item.Clear();

   string itemOut;

   unsigned int id;

   string first, last;

   in >>id >> first >> last >> item.aSize;

   item.setID(id);

   item.setFirst(first);

   item.setLast(last);

       for (int i = 0; i < item.aSize; i++)

   {

       in >> itemOut;

       item.CheckOut(itemOut);

   }

   return in;

}

ostream& operator<<(ostream& out, const Student& item)

{

   out << item.idNumb << " " << item.firstName << " " << item.lastName << endl;

   out << item.numItems << endl;

   for (int i = 0; i < item.numItems; i++)

   {

       out << item.pointy[i] << " ";

   }

   return out;

}

Student Student::operator+(Student &student1)

{

   Student anotherStudent;

   anotherStudent = student1;

   anotherStudent.CheckOut(itemName);

   return anotherStudent;

}

void Student:: operator+=(string& itemName)

{

   CheckOut(itemName);

}

bool operator==(Student & s1, Student &s2)

{

   if (s1.getID() == s2.getID())

       return true;

   else

       return false;

}

//student.h

#pragma once

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

class Student

{

protected:

   string firstName, lastName, itemName;

   unsigned int idNumb;

   int numItems, aSize;

   string* pointy = NULL;

public:

   //default constructor

   Student();

   //setters

   void setID(unsigned int nID);

   void setFirst(string nFirst);

   void setLast(string nLast);

   //getters

   int getID() { return idNumb; }

   string getFirst() { return firstName; }

   string getLast() { return lastName; }

   int CheckoutCount();

   //returns number of items student has checked out

   //takes a string parameter to describe an item

   bool CheckOut(const string& item);

   //checks if item is in if it is, checks it out

   //takes a string parameter to describe an item

   bool CheckIn(const string& item);

   //checks if item is checked out and deletes the array if so. a successful check in

   //returns true, if not it returns false.

   //takes an item parameter

   bool HasCheckedOut(const string& item);

   //checks if item is on the students checked out list

   void Clear();

   //clears the objects data

   //destructor

   ~Student();

   //Operator overloads

   friend istream& operator>>(istream& in, Student& item);

   //reads data in from text stream

   friend ostream& operator<<(ostream& out, const Student& item);

   //outputs data into text file

   Student operator+(Student &student1);

   //overloads the addition function adds an item to a student and outputs a new user

   void operator+=(string &itemName);

   //another way to add an item to a student and check it out

   bool friend operator==(const Student &item, const Student &item1);

   //checks if two students have the same id number or not

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote