Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Old 04-23-2009, 06:34 PM Final C++ Assignment
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
The teachers said this would be the TOUGHEST one yet, and at the same time, they're giving virtually NO help at all.

I struggled with the previous few assignments too, so I could really use the assistance.

So far the only code the assignment gave us were the function prototypes:
Code:
void init_num(int digits[], int aSize);
/*
Sets all of the elements of the digit array to 0, given the 
declared size of the array. 
*/

void get_num(int digits[], int aSize, int &eSize);
/*
Prompts the user to fill a digit array with at least one and at 
most aSize number of digits, -1 is used to signify that they are
done.  eSize is also set to the exact number of significant digits 
in the resulting number - [1 to aSize]. 
*/
   
void rev_num(int digits[], int eSize);
/*
Reverses the order of the significant digits in the digit array. 
*/
   
bool add_nums(int num1[], int eSize1, int num2[], int eSize2,
              int aSize, int num3[], int &eSize3);
/*
Given the two input digit arrays and their number of significant
digits (num1, eSize1, num2, eSize2) sets the values of the num3 
digit array and eSize3 to repressent the result of their addition.
Lastly, the function returns false if the final carry would exceed
the declared size (aSize) of num3 (overflow) and true otherwise.   
*/
   
void print_num(int digits[], int eSize);
/*
Given a number via its digit array and its number of 
significant digits, inserts the number onto the cout stream.
*/
And I literally have NO IDEA what to do next. I don't feel I did very well on the previous few either (they haven't even graded them or given us feedback yet!) and this is suppose to be due Monday, so again I feel kinda rushed here:
http://www.cs.uwm.edu/classes/cs201/.../09/09/09.html

I read over the assignment and even what they're asking of me is confusing. I know we're suppose to use an array to set most of this up, but that's about it.

If anyone could guide me through the core steps and concepts to understand what exactly I'm suppose to, I'd greatly appreciate it. Again neither the professors, nor the book (which was worse) were very helpful at all . Even if it's just one part at a time, I think it would help.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
 
Register now for full access!
Old 04-25-2009, 02:15 AM Re: Final C++ Assignment
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
*bump*
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 04-25-2009, 02:45 AM Re: Final C++ Assignment
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
How far can you go with the code? I can do every thing for you but it is not good since you have to thing about it.

anyway will give you some hints and part of the code
here is the code for the function init_num

Code:
void init_num(int digits[], int aSize)
{
/*
Sets all of the elements of the digit array to 0, given the 
declared size of the array. */
    for(int i=0;i<aSize;i++)
    {
        digits[i]=0;
    }
}
for getting data you need to use the function scanf
example:
Code:
scanf("%d",&digits[i]);
for displaying data use the function printf
example:
Code:
printf("some message : %d",digits[i]);
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 04-25-2009 at 04:20 AM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 04-25-2009, 03:13 AM Re: Final C++ Assignment
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Thanks for offering the help,

Quote:
Originally Posted by nayes84 View Post
How far can you go with the code?
What do you mean specifically? Like i said, I don't think the school has taught this course very well. I took it because I thought I'd be good at it and if anything, this course has turned me OFF to programming.

Anyway, I understand some basic programming concepts (I've done some PHP in the past), and C++ specifically, like cin for retrieving input and cout for displaying output, like using functions to reuse code blocks, and using 'return' to return whatever the portion of the program is asked to do. Not sure much about the stuff beyond that. They never really effictively taught the syntax of C++ very well, for example I know what an array is, and I know what functions are, but how I would create and implement this in C++, I have NO CLUE really.

I'd be especially appreciative as I think it would be very helpful if I could be walked through the process step-by-step. Although like you mentioned, it wouldn't be prudent to just give me the answer, I'm looking for the best way to understand the problem, and I'm not quite sure I do.

What would be the best way to go about this? Should I start by creating the functions? Designing the array? etc.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 04-25-2009, 04:09 AM Re: Final C++ Assignment
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
1- generally you need to look on what is required in the function and depending on that you can define what variables you need and if you need to output some thing to the user or get some input.
2- also when getting an input you need usually to check it to make sure it is valid or your program may crash if accessed out of bound element of an array for example or at least it will give wrong result.
3- after checking the inputs you need to decide what you need to do with the inputs like you need to store then in array or calculate something.

for example in the function get_num you need to get numbers from user
1- first you know you need to loop through the array digits[]
2- and on each cycle of the loop you need to prompt the user to input some number
3- then you need to check is it valid or not and if it is -1 you should finish out at this stage
4- otherwise you need to assign the inputted number in digits[i] then increase the counter up by using i++
5- and keep going till you reach aSize or when user press -1

try thinking the same way with all functions and you should be able to make it. if you have specific question about some function let me know
btw. it seems you don't use stdio.h instead you use iostream.h
so ignore my post regarding using scanf and printf instead you need to use cin and cout
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 04-25-2009, 01:12 PM Re: Final C++ Assignment
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Quote:
Originally Posted by nayes84 View Post
1- first you know you need to loop through the array digits[]
What does that mean? Am I supposed to create a type of loop for the array? Arrays are still a bit advanced for me, I think.

Quote:
Originally Posted by nayes84 View Post
2- and on each cycle of the loop you need to prompt the user to input some number
OK so how exactly do we prompt "on each cycle"? You mean just what's inside the squiggly brackets? Can't we only do that once?

Quote:
Originally Posted by nayes84 View Post
3- then you need to check is it valid or not and if it is -1 you should finish out at this stage
Validation is another thing they never explained very well, they just wrote an example up on the board and said "Here's what you need to validate..." with virtually no explanation at all why it works.

If I were to guess though, do we just use a simple if statement then in the 'else' part we just tell it to do it over again until it's correct somehow?

Quote:
Originally Posted by nayes84 View Post
4- otherwise you need to assign the inputted number in digits[i] then increase the counter up by using i++

5- and keep going till you reach aSize or when user press -1
Thankfully I understood what x++ (or x--) means, without there help. But I never knew quite exactly where it goes in the program, and how to stop it at a certain point. Or what the code is to get it to stop at aSize.


I'm thinking I might understand this better if I see an "example function" or something so I can understand what code is necessary to go where to complete everything that is being asked, and what exactly each piece of code will do, like you numbered.

Quote:
Originally Posted by nayes84 View Post
btw. it seems you don't use stdio.h instead you use iostream.h
so ignore my post regarding using scanf and printf instead you need to use cin and cout
[/quote]

Yeah I am using IOStream. Honestly, the professors told us to just write it down as it's a necessary part of the program, yet they wouldn't say wha it was for, so I have no idea exactly why we use it, we just do (and I wasn't sure what printf, scanf were ).

Personally I think everything they've introduced to us since the last time I asked for help is way to advanced for a beginner course, and at the same time they don't explain WHY we use the code that we do, we "just do". Again, thanks for all the help so far, if I could just understand the nuts and bolts of the syntax of C++, and it's variations against other languages, I would be good to go.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 04-25-2009, 02:02 PM Re: Final C++ Assignment
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
Quote:
What does that mean? Am I supposed to create a type of loop for the array? Arrays are still a bit advanced for me, I think.
you can't access or modify all of the elements of array in one step. you need a to loop through the array starting from element 0 till the last of the array
you can use any type of loop "for" loop, "while" loop or what ever you like

Quote:
OK so how exactly do we prompt "on each cycle"? You mean just what's inside the squiggly brackets? Can't we only do that once?
writing a code inside brackets of a loop structure will make it runs many times till the end of the loop.
Code:
int i=0;//initialization
while(i<aSize)
{
//write input code & checking code here and it will run aSize times
}
Quote:
If I were to guess though, do we just use a simple if statement then in the 'else' part we just tell it to do it over again until it's correct somehow?
yes you are correct you need to use if statement and concerning error processing I guess you need to make it prompt use to input again but it is better to ask your teacher about it.
mainly you need to check on two things
1- if inputs are valid or not
2- if input is -1 or not
you can implement those two things into a code like that
Code:
//well i'm assuming numbers should be between 0 & 999. but i don't know about the boundary you are required to do.it 
//depends on what the teacher asked you to do
if(num>=0&&num<999)//check for valid inputs
{
   //add the number to the array
   digits[i++]=num;
}
else if(num==-1)//check if user requested to exit
{
   eSize=i;
   break;//user typed -1 so just break out of the loop
}
else
{
   //show error message here
}
Quote:
Thankfully I understood what x++ (or x--) means, without there help. But I never knew quite exactly where it goes in the program, and how to stop it at a certain point.
you need to run x++ only in the case that input is valid and user didn't request to exit (entered -1)
in the past code
digits[i++]=num;
actually this does two things
1- assign num to digits[i]
2- increase i by 1
but i just made them in one step


Quote:
Or what the code is to get it to stop at aSize.
well as it should stops if it reached aSize you need to check on that at each cycle
the best and easiest way to do that is like i wrote before
while(i<aSize)
{
//code here
}
using while loop with checking if i<aSize will make it stop when i is not longer less than aSize
you can think of i as the number of current stored elements in digits. so when this number the same as aSize it means there is no more rooms for any new numbers or in another meaning it needs to get out of the loop.

Quote:
Personally I think everything they've introduced to us since the last time I asked for help is way to advanced for a beginner course, and at the same time they don't explain WHY we use the code that we do, we "just do".
for some one with good knowlege of c++ this shouldn't be too hard to do but I beleive it would be hard for a beginner. especially it uses some functionalities of c++ that not easy to understand from the first time
like reference pointers &eSize in
void get_num(int digits[], int aSize, int &eSize);besides it has many functions.
anyway good luck with your project
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 04-25-2009 at 02:09 PM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 04-25-2009, 11:32 PM Re: Final C++ Assignment
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Alright thanks for the tips. I figure I'll just try to get one part at a time working, but the thing is I can't tell if it's corrector not unless I compile an entire program, which puts me at somewhat of an impasse.

Well, these are the primary goals of the program:
Quote:
Write a program that allows its user to enter two non-negative whole numbers (with a maximum number of significant digits equal to 128), then adds the two numbers - storing the result into a third number. Lastly, display the two input numbers as well as the resulting number in some reasonable report format.
Based on the advice, here's what I'm thinking for the first one, something like:
Code:
void init_num(int digits[], int aSize)
{
while(aSize <= 128)
{
digits[0]
}


/*
Sets all of the elements of the digit array to 0, given the 
declared size of the array. 
*/
}
Am I doing the first function right? Not sure if I'm even on the right path here, or if the code is in the right spot (meaning in the right function); the entire assignment process is still very overwhelming.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 04-26-2009, 12:08 AM Re: Final C++ Assignment
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Going by the specs, init_num should just be setting all of the values in the array digits to zero
Code:
void init_num(int digits[] , int aSize)
{
     for(int i = 0; i < aSize; i++)
     {
          digits[i] = 0;
     }
}
The code you wrote is an infinite loop, and the body of the loop has no effect. If aSize does not change, while(aSize <= 128) will always be true or false. The line digits[0] does nothing (technically it accesses the first element in the array, but it is not stored or used so it has no effect).

Here is the while loop syntax for the function I wrote above:

Code:
void init_num(int digits[] , int aSize)
{
     int i = 0;
     while(i < aSize)
     {
          digits[i] = 0;
          i++;
     }
}
Both versions do the exact same thing (though I prefer the for loop syntax).

Regarding some of the code John posted:

Normally I wouldn't point this out, but since James is just picking up C++ I think its necessary to point out a few things you shouldn't do. First, lines like digits[i++] should never occur. Its confusing and easier to use incorrectly. Use the longer version that I used in my while loop above. Second, lines like if(num>=0&&num<999) are just difficult to read. Use spaces: if(num >= 0 && num < 999)
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 04-26-2009 at 12:21 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-26-2009, 12:34 AM Re: Final C++ Assignment
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
The code I wrote was just a stab in the dark, I honestly didn't know what the correct syntax was to get the function right. I'm still unclear of just what all that code you wrote, means, but I'll comment in it to show what my understanding of it is, even if it's completely wrong.
Code:
void init_num(int digits[] , int aSize)
{
     for(int i = 0; i < aSize; i++) 
     {
          digits[i] = 0;
     }
}
Not sure where the "i" integer came from. Is it just a placeholder you chose at random for the purpose of this function?

Also, what about aSize? The array numbers are suppose to be 128 so don't we equal the possibilities somewhere? Or is it declared globally? I mean, how does it know to stop increasing until it reaches 128?
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 04-26-2009, 12:47 AM Re: Final C++ Assignment
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
/*
Sets all of the elements of the digit array to 0, given the
declared size of the array.
*/
aSize is the size of the array. i is short for index, its really just a counter that I'm indexing the array with.

for(int i = 0; i < aSize; i++) means set i to 0, if i is less than aSize do what is in the body of the loop, and then increment i. It doesn't matter what variable you use for this. For example, all of these are valid:

Code:
//this will index the array in reverse
for(int j = (aSize - 1); j >= 0; j--)
{
     digits[j] = 0;
}

//this will multiply myVar by two until it is greater than or equal to 100
for(int myVar = 0; myVar < 100; myVar *= 2)
I don't know where 128 comes in, I just read the specs for the first function. Do you mean that each value in the array is supposed to be 128, or the array contains 128 values?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-26-2009, 01:06 AM Re: Final C++ Assignment
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
Quote:
Also, what about aSize? The array numbers are suppose to be 128 so don't we equal the possibilities somewhere? Or is it declared globally? I mean, how does it know to stop increasing until it reaches 128?
in the loop it checks on aSize right?
aSize is passed to init_num function as a parameter
so it will stop loop when i is not less than aSize any more
ptw. you shouldn't use global variables as much as possible instead pass needed data to the function
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 04-26-2009, 01:18 AM Re: Final C++ Assignment
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
OK I think I understand the syntax for that makes since then, thanks. I'll try taking a shot at the next function to see what I can come up with.

Quote:
Originally Posted by NullPointer View Post
I don't know where 128 comes in, I just read the specs for the first function. Do you mean that each value in the array is supposed to be 128, or the array contains 128 values?
The instructions state that "enter two non-negative whole numbers (with a maximum number of significant digits equal to 128)" , as I quoted from the instructions in post 8. So I thought we were suppose to set aSize equal to 128 somewhere.

Quote:
Originally Posted by nayes84 View Post
in the loop it checks on aSize right?
I'm not sure if it checks on it in the loop, all I know is that 128 is the maximum number of potential digits.

So if I'm understanding the instructions of my assignment correctly (I'm not even 100% sure about them), it is asking for the two numbers which can only be up to 128 digits, I think. (The link in my first post provides the instructions, even they sound pretty complicated for me, and this is my interpretation of them.)


Quote:
Originally Posted by nayes84 View Post
you shouldn't use global variables as much as possible instead pass needed data to the function
Maybe "declared" was the wrong word. I was trying to figure out if we set the aSize parameter in the int_main section of the program rather than specifically in the functions that we're creating here...
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 04-26-2009, 02:51 AM Re: Final C++ Assignment
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by jamestl2 View Post
The instructions state that "enter two non-negative whole numbers (with a maximum number of significant digits equal to 128)" , as I quoted from the instructions in post 8. So I thought we were suppose to set aSize equal to 128 somewhere.
I think that only corresponds to that particular question, the solution I posted was for the first function, which should be independent. Your assignment is to implement each of these functions correct? I assumed that was the case because each of these functions actually don't have any effect because all the parameters are passed by value rather than by reference (that probably doesn't make sense at this point).
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-26-2009, 12:07 PM Re: Final C++ Assignment
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Code:
void get_num(int digits[], int aSize, int &eSize)
{
do
{
cin >> eSize;
}
while(aSize < 128);

asize == -1;


/*
Prompts the user to fill a digit array with at least one and at 
most aSize number of digits, -1 is used to signify that they are
done.  eSize is also set to the exact number of significant digits 
in the resulting number - [1 to aSize]. 
*/
}
Quote:
Originally Posted by NullPointer View Post
I think that only corresponds to that particular question, the solution I posted was for the first function, which should be independent. Your assignment is to implement each of these functions correct? I assumed that was the case because each of these functions actually don't have any effect because all the parameters are passed by value rather than by reference (that probably doesn't make sense at this point).
Well, I'm suppose to get the program working, basically by writing functions and implementing them in some form in int_main. Also, the next function does use a reference parameter, I think (Ref. Parameters are still too advanced for an Intro. to C++ class, in my opinion), so they are passed by ref. next here.

Anyway, since we're using one for the next function specifically, that's what I'm thinking we're suppose to use for input, right?

And honestly, I have no idea where (or exactly how) to set aSize to -1. I hope I'm on the right track.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 04-26-2009, 02:43 PM Re: Final C++ Assignment
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
eSize is passed by reference, the others are still passed by value.

The description for that particular function isn't very clear to me. If I had to guess I'd say they were asking you to prompt the user for input aSize number of times, and set the next value in the array to that value. If the user inputs -1 you break.

Code:
void get_num(int digits[], int aSize, int &eSize)
{
     int input = 0;
     eSize = 0;

     while(input != -1 && eSize < aSize)
     {
          cout << "Input next value" << endl;
          cin >> input;
          digits[eSize] = input;
          eSize++;
     }
}
That's just my guess.

I still don't understand where 128 comes into this.

To set aSize to -1 all you do is
Code:
aSize = -1;
= sets a value, == compares two values.

}
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-26-2009, 10:44 PM Re: Final C++ Assignment
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
(Sorry, I had a power outage since 1PM today and didn't get it back until just now, kinda frustrating.)

I thought that was what I was doing with last function *sigh* was alright. I still don't know why I'm not getting this .

Quote:
Originally Posted by NullPointer View Post

The description for that particular function isn't very clear to me. If I had to guess I'd say they were asking you to prompt the user for input aSize number of times, and set the next value in the array to that value. If the user inputs -1 you break.

That's just my guess.
The function 'get-num' is just asking for the person to "fill a digit array", which I think means the number of places the number given by the user can be. -1 still confuses me though.


Quote:
Originally Posted by NullPointer View Post
I still don't understand where 128 comes into this.
I may be misunderstanding what it's for, but it mentions it right at the beginning of the assignment. 128 is just the highest amount of digits a user can enter for one of the numbers.



Again thanks for all the help everyone, especially on short notice. I'll definitely provide more TP once I get the opportunity to spread some more around. It's been very helpful .
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 04-26-2009, 10:50 PM Re: Final C++ Assignment
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
So is 128 the maximum value that can be stored as an element in the array, or is 128 the maximum number of values that can be stored in the array (the size of the array). I know how to implement the functions, its the descriptions that were provided to you that confuse me (not your fault of course).
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-26-2009, 11:01 PM Re: Final C++ Assignment
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
The second one I'm pretty sure. The numbers the user enters can have up to 128 digits. No one can really put the value "128" in a single section of the array.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 04-27-2009, 01:58 AM Re: Final C++ Assignment
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
well again when you use while loop for example
Code:
i=0;
while(i<aSize)
{
//some code here
//increase i by 1 when a successful input is made
}
that code simply check on the size of the array at each cycle.
i<aSize means the loop will continue till i is not longer less than aSize
say if aSize=128
and i start from 0 of course
then if the user kept typing numbers. it will loop and increase i by 1 each time.
i=0,1,2,...128
once it is 128 the condition "i<aSize" is not longer true so simple will get out of the loop
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Final C++ Assignment

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.58281 seconds with 12 queries