We have to enter numbers in a spread sheet. Our lab gives us the code for the main function, and we have to write the code the read the spreadsheet, then the two sub functions. The sub functions add the rows and columns and then displays them.
What I'm not sure of is how to enter and get data so the user enters it like this:
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
Just the form of the spaces going across.
Current co
Code:
//Lab 13 - Spreadsheets
#include <iostream>
using namespace std;
//Function protostypes
int sumcol(int ss [ ][100], int col, int numrows);
int sumrow(int ss [ ][100], int row, int numcols);
int sumcol(int ss [ ][100], int col, int numrows, int j)
{
for (j=0;j < col; j++){
}
return j;
}
int sumrow(int ss [ ][100], int row, int numcols, int k)
for (k=0; k < row; k++){
}
return k;
}
int main ()
//Purpose: Read a spreadsheet and sum its rows and colums
//Preconditions: None
//Postconditions: displays the spreadsheet the sums of its rows and colums
{
int ss[100][100]; //spreadsheet
int numrows; //number of rows in spreadhsheet
int numcols; //number of columns in spreadsheet
int j,k; //loop variables
//Get the size of the spreadsheet
cout << "Enter number of rows (<= 100): ";
cin >> numrows;
cout << "Enter number of columns(<=100): ";
cin >> numcols;
//Read the spreadsheet
cout << "Enter data for spreadsheet:" << endl;
// Add code to read spreasheet here.
//Display spreadsheet and sums of rows
cout << endl << endl << "Sums of Rows and Columns" << endl;
for (j=0; j <numrows; j++) {
for (k=0; k<numcols; k++) {
cout << ss[j][k] << "\t" ;
}
cout << " | " << sumrow <<(ss, j, numcols) << endl;
}
//Display sums of columns
for (j=0; j<numcols; j++) {
cout << "---" << "\t" ;
}
cout << endl;
for (j=0; j<numcols; j++) {
cout << sumcol (ss, j, numrows) << "\t";
}
cout << endl;
return 0;
}
AJ