C++ help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

C++ help

 
0
  #1
Aug 15th, 2004
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++
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 22
Reputation: WhataNerd is an unknown quantity at this point 
Solved Threads: 0
WhataNerd WhataNerd is offline Offline
Newbie Poster

Re: C++ help

 
0
  #2
Aug 17th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: C++ help

 
0
  #3
Aug 17th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Re: C++ help

 
0
  #4
Aug 17th, 2004
Sorry for opening it... :cry:
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 22
Reputation: WhataNerd is an unknown quantity at this point 
Solved Threads: 0
WhataNerd WhataNerd is offline Offline
Newbie Poster

Re: C++ help

 
0
  #5
Aug 19th, 2004
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC