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

C++ Project. For this project, you will create a class for an elementary school

ID: 3738334 • Letter: C

Question

C++ Project.

For this project, you will create a class for an elementary school that will allow a teacher to enter each student's seating assignment. Occasionally, the teacher may need to switch the seating assignment of a student. If there is a seat available, the student is moved. If all of the seats are already assigned, the teacher will have two students trade seats.      

Minimum Requirements:

Create a class that has a string array of size 20 as a private data member. You cannot use a vector for this assignment (5 points).

Include a function to add students to the seating chart array (5 points). Position 0 of the array represents the seat closest to the teacher's desk. The array index will represent each seat number for the seating assignments.

Include a function that will accept a student name and a target seat. This function should find the students name in the array and move the student's name from his or her original seat to the target seat. If the target seat is empty, move the student's name to the target seat. If the target seat is not empty, swap the names of the students so they trade seating assignments. (5 points).

Explanation / Answer

/******************************************************************************

Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <string>

using namespace std;

class SeatingArranger
{
private:
int currentSeatIndex;
int arraySize;
string *seatArray;
  
public:
SeatingArranger()
{
currentSeatIndex = 0;
arraySize = 20;
seatArray = new string[arraySize];
}
  
~SeatingArranger()
{
delete seatArray;
}
  
void AddStudent(string studendName)
{
seatArray[currentSeatIndex] = studendName;
currentSeatIndex++;
  
if(currentSeatIndex == arraySize)
{
arraySize = arraySize + 2;
  
std::string *newArray = new std::string[arraySize];
  
for(int i = 0; i < currentSeatIndex; i++)
{
newArray[i] = seatArray[i];
}
  
seatArray = newArray;
}
}
  
void MoveStudent(string studendName, int targetPosition)
{
if(targetPosition >= arraySize)
{
cout<< "Target position is greater than available seats"<<endl;
return;
}
else
{
int studentIndex = 0;
bool found = false;
  
for(int i = 0; i < arraySize; i++)
{
if(seatArray[i] == studendName)
{
studentIndex = i;
found = true;
cout<<"Seat found at "<<i<<" position"<<endl;
}
}
  
if(found)
{
if(targetPosition >= currentSeatIndex)
{
cout<<"Seat is empty..performing operation"<<endl;
seatArray[targetPosition] = studendName;
seatArray[studentIndex] = '';
}
else
{
cout<<"Seat is not empty.. performing swapping"<<endl;
seatArray[studentIndex] = seatArray[targetPosition];
seatArray[targetPosition] = studendName;
}
}
}
}
  
void Display()
{
cout<<"=============================="<<endl;
cout<<"Students arrangement"<<endl;
  
for(int i= 0; i<arraySize; i++)
{
cout<<seatArray[i]<<" ";
}
  
cout<<endl;
}
};

int main()
{
SeatingArranger sA;
  
cout<<"Seating arrangement demo"<<endl;
  
while(true)
{
int choice;
cout<<"1. To add students"<<endl;
cout<<"2. To change student's seat"<<endl;
cout<<"3. To display arrangement"<<endl;
cout<<"4. To quit"<<endl;
cin>>choice;
  
switch(choice)
{
case 1:{
  
string studentName;
cout<<"Enter the student name"<<endl;
cin>>studentName;
sA.AddStudent(studentName);
}
break;
case 2:{
  
string studentName;
cout<<"Enter the student name to search"<<endl;
cin>>studentName;
int targetPosition;
cout<<"Enter the target position for the entered student"<<endl;
cin>>targetPosition;
sA.MoveStudent(studentName,targetPosition);
  
}
break;
case 3:{
sA.Display();
}
break;
case 4:
break;
default:
break;
}
  
if(choice == 4)
{
break;
}
}

return 0;
}

//PLEASE PROVIDE FEEDBACK THUMBS UP

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