hi, i have been going crazy trying to figure this out so if anyone can help that would be great. i have created a class with a data item of type char which is a two dimensional array.
there are three functions first i want to read a file which i am able to do but the second function wants me to display the textfile using a two dimensional array.
this is my code at the moment:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using std::ifstream;
using std::ofstream;
using std::endl;
using std::cout;
#include <iostream>
#include <fstream>
#include <string>
#include "auditorium.h"
using std::ifstream;
using std::ofstream;
using std::endl;
using std::cerr;
usingnamespace std;
int main()
{
auditorium a;
a.readSeatsConfig();
a.displaySeatsConfig(char[][30], int size);
system("pause");
return 0;
}
im also trying to get a seat which will be in the function getSeatClass, so is there a way to select a value by row and buy column in a two dimensional array ive been trying to find codes over the internet but i havent found anything yet :(
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using std::ifstream;
using std::ofstream;
using std::endl;
using std::cout;
usingnamespace std;
class auditorium
{
private:
char seats [14][30];
public:
void readSeatsConfig();
void displaySeatsConfig(); // no need for parameters, it gets the info from seats
char getSeatClass(int, int); // you want to find the class by giving row and column,
// therefor you must return a char and take two ints for row and column
};
void auditorium::readSeatsConfig(){
ifstream infile;
infile.open("seatsConfig.txt");
if (infile.fail())
{
cerr <<"file does not exist"<<endl;
}
else{
cerr<<"Reading text file"<<endl<<endl;
for (int i = 0; i < 14; ++i) // this is where you need your nested for loops to read in
for (int j = 0; j < 30; ++j) // just like you did in displaySeatsConfig, but you're
// retreaving data from file, so use >>
infile >> seats[i][j];
}
infile.close();
}
void auditorium::displaySeatsConfig() {
// we're reading in with the readSeastsConfig() function, here we just want display from seats.
// We're displaying, so use cout
for (int index1=0; index1<14; index1++) {
for (int index2=0; index2<30; index2++)
cout << seats[index1][index2];
cout << endl;
}
}
char auditorium::getSeatClass(int row, int column) {
// just use the [][] to get the char from the corresponding row and column
return seats[row][column];
}