Does anyone know how to do this This a slightly modified ver
Does anyone know how to do this?! This a slightly modified version of the original Java lockers problem but uses extensive array! Thank you so much!
A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, opens every locker. Then the second student, S2, begins with the second locker, denoted L2, and closes every other locker. Student S3 begins with the third locker and changes every third locker (closes it if it was open, and opens it if it was closed). Student S4 begins with locker L4 and changes every fourth locker. Student S5 starts with L5 and changes every fifth locker, and so on, until student S100 changes L100. After all the students have passed through the building and changed the lockers, which lockers are open?
Write a program (class) to find your answers & Don’t forget a legend
Assume: 1) all lockers are initially closed (false) and there is a Legend but no input. 2) the Boolean array name is lockers.
The class should have
a) A Main method with the honor code, comments that describe the problem, including input and output in your own words and calls to the 3 work methods.
b) An OpenLocker method that accepts an array, a starting position, and an increment and
c) A CloseLocker method that accepts an array, a starting position, and an increment.
d) A PrintOpen method that prints which lockers are open at the end.
The program should display the answer something like this:
Locker x is open
Locker y is open
…
Locker z is open
Solution
#include <iostream.h>
#include <conio.h>
#include <apvector.h>
#include <apstring.h>
#include <apstring.cpp>
#include <iomanip.h>
//#include \"title.cpp\"
class LockerClass
{
private:
struct LockerType
{
int LockerNum;
bool Status;
double Money;
};
public:
apvector <LockerType> Lockers;
LockerClass();
~LockerClass();
void ChangeStatus();
void DisplayOpenClose();
void LockerMoney();
void LockerSort();
};
void main()
{
LockerClass School;
School.ChangeStatus();
School.DisplayOpenClose();
School.LockerMoney();
School.LockerSort();
}
LockerClass::LockerClass()
{
Lockers.resize(1000);
for (int K = 0; K < 1000; K++)
{
Lockers[K].LockerNum = K +1;
Lockers[K].Status = false;
Lockers[K].Money = 0;
}
}
LockerClass::~LockerClass()
{
}
void LockerClass:: DisplayOpenClose()
{
clrscr();
int K; int N; apstring Open;
N = Lockers.length();
//Title(\"Locker Status\");
for (K = 0; K < N; K++)
{
if (Lockers[K].Status == 0)
Open = \"closed\";
else
Open = \"open\";
cout << \"Locker[\" << Lockers[K].LockerNum << \"]\" << \"\\t\";
cout << setw(15) << \"Status: \" << Open << \"\\t\";
cout << setw(20) << \"Money: \" << Lockers[K].Money;
cout << endl;
if (K%20 == 0)
getch();
}
}
void LockerClass::ChangeStatus()
{
for (int K = 1; K < 1000; K++)
for (int N = 1; N < 1000; N++)
{
if (N % K == 0)
{
if (Lockers[N].Status == 0)
Lockers[N].Status = 1;
else
Lockers[N].Status = 0;
}
}
}
void LockerClass::LockerMoney()
{
/*
int K;
double Money;
//Title(\"Locker Money Function\");
if (Lockers[K].LockerNum == 0)
Lockers[K].Money+=.25;
*/
}
void LockerClass::LockerSort()
{
getch();
}


