943,724 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2693
  • C++ RSS
Aug 15th, 2004
0

C++ help

Expand Post »
Can anybody help me with some or all of these problems?

Problem 1:

Write the definition of a function minMax that has five parametersª. The first three parametersª are integersª. The last two are set by the function to the largest and smallest of the valuesª of the first three parametersª. The function does not return a valueª.
The function can be used as follows:
intª a=31, b=5, c=19 big, small; minMax(a,b,c,&big,&small); /* big is now 31 */ /* small is now 5 */

I think the answer is

void minMax(int a, int b, int c, int* big, int* small){
if(a<c && a<b)*small=a;
else if(b<c && b<a)*small=b;
else if(c<a && c<b)*small=c;
else if(a>b && a>c)*big=a;
else if(b>a && b>c)*big=b;
else if(c>a && c>b)*big=c;
}

Problem 2:

Givenª the charª *variablesª name1, name2, and name3, write a fragment of code that assignsª the largest valueª to the variableª max (assumeª all three have alreadyª been declaredª and have been assignedª valuesª).

I think the answer is

if(strcmp name1>strcmp name2 &&strcmp name1>strcmp name3)max=name1;
else if(strcmp name2>strcmp name1 && strcmp name2>strcmp name3)max=name2;
else if(strcmp name3>strcmp name1 && strcmp name3>strcmp name2)max=name3;

Problem 3:

Write a sequence of statementsª that finds the first comma in the stringª line, and assignsª to the variableª clause the portion of line up to, but not including the comma. You may assumeª that an intª variableª pos, as well as the variablesª line and clause, have alreadyª been declaredª.

I think the answer is

pos.line(",");
clause=line.substr(0,pos-1);

Problem 4:

Write a function called printStars. The function receives an intªparameterª. If the parameterª is positive, the function prints (to standard outputª) the givenª number of asterisks; otherwise the function does nothing. The function does not return a valueª. Thus, if the printStars(8) is called, ******** (8 asterisks) will be printed.
The function must not use a loop of any kind (for, while, do-while) to accomplish its job. Instead, it gets the job done by examining its parameterª, returning if the parameterª's valueª is not positive. If the parameterª is positive, it
prints a single asterisk (and no other charactersª)
then (recursively) calls itself to print the remaining asterisks.

I think the answer is

int i = 0;
void printStars(int starCount){
if(starCount>0){
if(i<starCount){
cout<<"*";
starCount;
i++;
printStars(starCount);
}
}
}

Thank you SO much,
C++
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Aug 17th, 2004
0

Re: C++ help

ahhh cmon no one's gonna help the man????......he even tried all of the problems out and posted his gues for the answers....he posted it 3 days ago and 0 rplays so far. I'd answer but i don't know much about programming so yea
Reputation Points: 10
Solved Threads: 0
Newbie Poster
WhataNerd is offline Offline
22 posts
since Jul 2004
Aug 17th, 2004
0

Re: C++ help

He opened another thread with the same question and that has had a lively set if interactions in it. That's probably why there's not much here.
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Aug 17th, 2004
0

Re: C++ help

Sorry for opening it... :cry:
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Aug 19th, 2004
0

Re: C++ help

o ok im sorry i did'nt see that he did that.........i just wanted to point out that no one was helping him out but obviously i was wrong, because it was all answered in the other thread. Sorry for the mix up
Reputation Points: 10
Solved Threads: 0
Newbie Poster
WhataNerd is offline Offline
22 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: how to start out
Next Thread in C++ Forum Timeline: C program doubts





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC