Quantcast

Maximum PC

It is currently Sun Aug 31, 2014 1:59 am

All times are UTC - 8 hours




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: C++ Lab help...no not the whole thing :p
PostPosted: Thu Oct 09, 2008 6:33 am 
Team Member Top 1000
Team Member Top 1000
User avatar

Joined: Thu Sep 11, 2008 4:10 pm
Posts: 868
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


Top
  Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 6:38 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
Location: Granite Heaven
No question, no answers.

If you haven't posted an actual question by the end of the day, I'll lock the thread.

Don't post a big long hunk of code that no one is going to examine ... ask a specific question. Ie., "I need to read in data from a user and I'm not sure where to start."


Top
  Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 6:46 am 
Team Member Top 1000
Team Member Top 1000
User avatar

Joined: Thu Sep 11, 2008 4:10 pm
Posts: 868
Quote:
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.


That was my questions....sorry for not being clearer. Basically, how do I get the data from the user in that form?

EDIT: Nevermind...I got everything. Whole program works.

AJ


Top
  Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 8:15 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
Location: Granite Heaven
:) Cool.

In the future:

a) how do I get data from a user;
b) how do I parse data from a user;
c) how do I format data from a user.

The key to programming is knowing how to break a problem into its most elementary steps.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Dec 25, 2008 8:46 pm 
Little Foot
Little Foot

Joined: Sat Feb 11, 2006 11:04 am
Posts: 174
1) How to get data from users:
//Given that the following variables are declared
cin >>x >>y >>z >>c (this gets 4 inputs from users)
2) Display in rows
cout<< x <<" " <<y <<" " <<z<<" " <<c<<endl;

e.g. You can also format the columns and rows by using the setw() function.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group