C++ Homework

Sicklyboy

#JOYCONBOYZFOREVER
OP
Global Moderator
Joined
Jul 15, 2009
Messages
6,313
Trophies
2
Location
[̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]
XP
8,137
Country
United States
So yeah, I am stuck in shit right now with this. The main thing I am having problems with is I have NO idea how to pass a matrix (2 dimensional array) to a function.

My (unfinished) code (yeah, there is no purpose in this program yet, I just need to get it to run).

Code:
//plane.h
#ifndef plane_h
#define plane_h

#include 
#include 
#include 
#include 
#include 

using namespace std; //standard namespace
//prototypes
bool extern openInFile (const char *, ifstream&);
void extern getFirst(ifstream&, int&, int&, int&, int&);
void extern fillChart(ifstream&, int*[], int, int);
#endif
Code:
//main.cpp
#include "plane.h"

int main()
{
int fRows = 0;
int fSeats = 0;
int eRows = 0;
int eSeats = 0;
ifstream dataFile;//input file stream
bool fileOpen = false;//bool value to check if file is open
int* A = NULL;

fileOpen = openInFile ("Airplane.txt", dataFile); //attempts to open file
if(!fileOpen) //if file isnt open, ends program
return 1;
getFirst(dataFile, fRows, fSeats, eRows, eSeats);
int fChart[fRows][fSeats];
int eChart[eRows][eSeats];
for(int i = 0; i < fRows; i++)
for(int j = 0; j < fSeats; j++)
fChart[i][j] = 0;
for(int i = 0; i < eRows; i++)
for(int j = 0; j < eSeats; j++)
eChart[i][j] = 0;
A = *fChart;
fillChart(dataFile, A, fRows, fSeats);
A = *eChart;
fillChart(dataFile, A, eRows, eSeats);

return 0; //ends the program
}
Code:
//process.cpp
#include "plane.h"

void getFirst(ifstream &infile, int &fRows, int &fSeats, int &eRows, int &eSeats);
{
infile.get(fRows, 2, ' ');
infile.get(fSeats, 2, ' ');
infile.get(eRows, 2, ' ');
infile.get(eSeats, 2, ' ');
}

void fillChart(ifstream &infile, int*[] chart, int r, int c)
{
int temp = 0;
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
infile.get(temp, 2, ' ');
cout
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Psionic Roshambo @ Psionic Roshambo: https://www.youtube.com/watch?v=KYZD7ykz9aQ