# Maximum PC

 It is currently Sat Apr 25, 2015 7:20 am

 All times are UTC - 8 hours

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: C++ Lab help...no not the whole thing :pPosted: Thu Oct 09, 2008 6:33 am
 Team Member Top 1000

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:

#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 ()
//Preconditions: None
//Postconditions: displays the spreadsheet the sums of its rows and colums
{
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;

cout << "Enter data for spreadsheet:" << endl;

//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

 Post subject: Posted: Thu Oct 09, 2008 6:38 am
 Java Junkie

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24245
Location: Granite Heaven

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

 Post subject: Posted: Thu Oct 09, 2008 6:46 am
 Team Member Top 1000

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

 Post subject: Posted: Thu Oct 09, 2008 8:15 am
 Java Junkie

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24245
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

 Post subject: Posted: Thu Dec 25, 2008 8:46 pm
 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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC - 8 hours

#### Who is online

Users browsing this forum: No registered users and 3 guests

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

Search for:
 Jump to:  Select a forum ------------------ Maximum FAQs    Forum Rules, Posting Guidelines & Announcements    The Good, The Bad & The Banned    FAQs Help/Do It Yourself    PC Building Lab    The Help Desk    PC Modding    Education & Certification Hardware    Nuts & Bolts    Portable Talk    Appraisals, Deals & Bargains (oh my!) OS/Software/Programming    Windows Parlor    Alt.OS.Abode    Games Arena    Programmers' Paradise Networking/Internet    Internet Truckstop    Network Nook In/Out    Magazine and Book Feedback    Forum & Website Feedback    Dog Pound Team Maximum PC Folding at Home    Team Maximum PC - Folding at Home - FIND CURES TO DISEASES    Team MPC - Folding Gauntlets