Question
Please take a look at my code and tell me why i get the following error: My code is comprised of 3 files. Cplane.cpp, Cplane.h
Please take a look at my code and tell me why i get the following error:
My code is comprised of 3 files. Cplane.cpp, Cplane.h , and Cmain.cpp . Ill will post the post here:
Cmain.cpp
#include
#include "Cplane.h"
using namespace std;
int main() {
Plane COSC1430;
//COSC1430.displaySeats();
while (1)
{
cout
cout
cout
cout
cout
cout
cout
cout
int ch;
cin >> ch;
switch (ch)
{
case 1:
COSC1430.displaySeats();
break;
case 2: COSC1430.checkSeat();
break;
case 3: COSC1430.clearSeat();
break;
case 4: COSC1430.bookSeat();
break;
case 5: COSC1430.clearAllseats();
break;
case 6: COSC1430.~Plane();
exit(0);
break;
}
}
system("pause");
return 0;
}
==============Cplane.h============================
#pragma once
#ifndef PLANE_H
#define PLANE_H
struct Seat
{
char status;
bool isBooked;
};
class Plane
{
private:
Seat **firstClass;
Seat **economy;
int firstClassRows;
int firstClassCols;
int econRows;
int econCols;
public:
//default constructor
Plane();
//overloaded contructor
Plane(int r11, int c11, int r21, int c21);
//other functions
void displaySeats();
void bookSeat();
void checkSeat();
void clearSeat();
void clearAllseats();
~Plane();
};
#endif
==============Cplane.cpp==========================
#include
#include
#include "Cplane.h"
using namespace std;
Plane::Plane()
{
int r11, c11, r21, c21;
cout
cin >> r11;
cout
cin >> c11;
cout
cin >> r21;
cout
cin >> c21;
cout
Plane(r11, c11, r21, c21);
}
Plane::Plane(int r1, int c1, int r2, int c2)
{
//this->firstClassRows = r1;
//this->firstClassCols = c1;
//this->econRows = r2;
//this->econCols = c2;
firstClassRows = r1;
firstClassCols = c1;
econRows = r2;
econCols = c2;
//initalize first class array
firstClass = new Seat *[r1];
for (int i = 0; i
firstClass[i] = new Seat[c1];
}
for (int i = 0; i
for (int j = 0; j
firstClass[i][j].status = '-';
firstClass[i][j].isBooked = false;
}
}
//initalize economy class array
economy = new Seat *[r2];
for (int i = 0; i
economy[i] = new Seat[c2];
}
for (int i = 0; i
for (int j = 0; j
economy[i][j].status = '-';
economy[i][j].isBooked = false;
}
}
}
//function to display the seats
void Plane::displaySeats()
{
cout
cout
cout
cout
for (int i = 0; i
{
for (int j = 0; j
{
cout
}
cout
}
cout
cout
for (int i = 0; i
{
for (int j = 0; j
{
cout
}
cout
}
}
//function to book the seats
void Plane::bookSeat() {
cout
int ch, r, c;
cin >> ch;
bool booked = false;
while (!booked)
{
cout
cin >> r >> c;
switch (ch)
{
case 1:
if (firstClass[r - 1][c - 1].isBooked == false) {
firstClass[r - 1][c - 1].isBooked = true;
firstClass[r - 1][c - 1].status = '*';
cout
booked = true;
break;
}
else
{
cout
booked = false;
break;
}
case 2:
if (economy[r - 1][c - 1].isBooked == false) {
economy[r - 1][c - 1].isBooked = true;
economy[r - 1][c - 1].status = '*';
cout
booked = true;
break;
}
else
{
cout
booked = false;
break;
}
}
}
}
//function to check a seat
void Plane::checkSeat() {
cout
int ch, r, c;
cin >> ch;
cout
cin >> r >> c;
if (ch == 1)
{
cout
}
else if (ch == 2)
{
cout
}
else
{
cout
}
}
//function to clear the seats
void Plane::clearSeat()
{
cout
int ch, r, c;
cin >> ch;
cout
cin >> r >> c;
if (ch == 1)
{
cout
firstClass[r - 1][c - 1].isBooked = false;
firstClass[r - 1][c - 1].status = '-';
}
else if (ch == 2)
{
cout
economy[r - 1][c - 1].isBooked = false;
economy[r - 1][c - 1].status = '-';
}
else
{
cout
}
}
void Plane::clearAllseats() {
for (int i = 0; i
for (int j = 0; j
firstClass[i][j].status = '-';
firstClass[i][j].isBooked = false;
}
}
for (int i = 0; i
for (int j = 0; j
economy[i][j].status = '-';
economy[i][j].isBooked = false;
}
}
}
//class destructor
Plane::~Plane()
{
delete firstClass;
delete economy;
}
=================================
Lastly here is the output with the values i entered to test the program:
thank you! i would appreciate details so i can understand whats wrong and apply it in the future.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 outTheseat is hooked:firstClass was 0x111011E economy r-1c -1 Copy Details Exception Settings Break when this exception type is thrown Except when thrown from Chegg-Plane.exe Open Exception Settings Edit ConditionsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started