Tuesday, July 14, 2009

Help C++ experts can u make me a prog that inputs 10 int numbers then displays the highest and lowest then?

computes the ave of the lowest and highest numbers

Help C++ experts can u make me a prog that inputs 10 int numbers then displays the highest and lowest then?
Off the top of my head





include %26lt;iostream.h%26gt;


main{


int[10] n;





cout %26lt;%26lt; "enter ten numbers" %26lt;%26lt; endl;


for (int i = 0; i %26lt; 10; i+=2)


{


cin %26gt;%26gt; n[i]


}





int biggest = 99999, littlest = -999999;





for (int j = 0; j %26lt; 10; j++)


{


if n[j] %26lt; littlest


littlest = n[j]


else if n[j] %26lt; biggest


biggest = n[j]


}





int avg = biggest + littlest /2;


cout %26lt;%26lt; avg %26gt;%26gt; endl;


}
Reply:I like the errors ;P Report It

Reply:anyone can write a simple progran like that, the question is, can you do it in O(log(n)) time?





Steve S - Good one!
Reply:yes, yes I can. Actually you know I was assigned to do the same assignment in my class, so no, no I wont. My services don't come free, you pay like everyone else.





BTW, it really doesn't take an expert to make a program that is that simple.
Reply:And you think I should do the learning for you why? And who will be there to do your work after graduation so you can file your nails, surf the web and pick up your paychecks for nothing? Do it yourself.
Reply:C'mon man do your own homework
Reply:the question is too difficult for an ordinary c++ expert. try mailing it to bill gates


In c++,why can't we assign a void pointer to an int type pointer?

do this





void* vp;


int* ip;





ip=(int*)vp;

In c++,why can't we assign a void pointer to an int type pointer?
Because they're different data types, one is a pointer to an int, and the other is not :-) They're all just memory addresses though, so if you know what you're doing then you can typecast one to the other.
Reply:Because doing so, without a really good reason, is a very bad idea. The compiler warning / error for that attempted assignment is a safeguard to keep programmers from making silly mistakes. If you get this kind of a message, it is very likely that your program's data design is flawed or poorly thought out.





However, C++ will allow you to make that kind of assignment using an explicit typecast. Using a typecast is the same as telling the compiler that you know what you are doing, and take full responsibility for the consequences of that kind of assignment and any side effects which may occur.


How do I force my C++ program to output leading zeros when dealing with an int value?

I'm writing a program that deals with times on a stopwatch, and I've designated a private member variable for both minutes and seconds. However, when I try to print out to the screen the results of this work, I can't seem to get a leading zero to show up for the seconds column for values between 0 and 9.





Any advice?

How do I force my C++ program to output leading zeros when dealing with an int value?
You can use manipulators to change the properties of some stream display:-





int second = 5;


cout %26lt;%26lt; setfill('0') %26lt;%26lt; setw(2) %26lt;%26lt; second;





Output:- 05.





The setfill(char padding) manipulator will set the padding character.


The setw(int width) manipulator will set the width of the displayed value.
Reply:Or if you are using the C-style printf function, add a leading zero to the format string, like so:





printf("%02u:%02u", minutes, seconds);





The 2 means two characters wide, and the 0 means left-pad with zeros.

rose

Y=mx+b ax+by+c=0 x/a+y/b=1 where a= x int b=y int?

i dont get this is this some kind of formula can some one explain it to me please?

Y=mx+b ax+by+c=0 x/a+y/b=1 where a= x int b=y int?
they are formulas for plotting lines, u put numbers in to the vaules, such as the first one; y=mx+b, it would be y=2x+5 which would be a line going through 5 on the y axis and in a direction of up and to the right and down and to the left


Write a quadratic function f(x) = ax2 + bx+ c for this parabola described. Min. value = -5 x int = -2 & 3?

alg 2 help!

Write a quadratic function f(x) = ax2 + bx+ c for this parabola described. Min. value = -5 x int = -2 %26amp; 3?
Your parabola will be of the form f(x) = k*(x-int1)(x-int2) where int1 and int 2 are the intercepts given and then you adjust k so that f(x) passes through that minimum. So f(x) = k*(x+2)*(x-3).





The minimum is going to happen half way between the two intercepts, or at x=.5, and f(.5) = k*2.5*(-2.5) = -6.25k which is supposed to be -5 from the problem. So then k must be .8 (since .8 * -6.25 = -5) and your polynomial is:





f(x) = .8(x+2)(x-3) = .8x^2 - .8x - 4.8
Reply:(1) f(3)=0=9a+3b+c


(2) f(-2)=0=4a-2b+c subtract


(3) 0=5a+5b





min @x=1/2


(4) f(1/2)=-5=.25a+.5b+c subtract this from (1)





(5) 3.75a-2.5b=5 double this


(6) 7.5a-5b=10 add to (3)


(7) 12.5a=10


a=.8


substitute in (3)


.8*5+5b=0


b=-.8


substitute values of a %26amp; b into (1)


0=.8*9-.8*3+c


c=-6*.8=-.48


f(x)=.8x^2-.8x-.48


Does the size of an int depend on how many bits the processor is? c#?

The compiler is the only thing that matters for the number of bits used to represent an int.





Two different compilers on the same machine, with the same processor might cause an int to be 16 bits or 32 bit. It all depends on the compiler.





In practice, most compilers are writen for a specific hardware achitecture. Compilers usually make the int type as wide as a general purpose register for the target hardware.

Does the size of an int depend on how many bits the processor is? c#?
It really depends on the language and the compiler. In C++, if you switched to 64 bit programming, the language may redefine int to be 64 bits, making that code incompatible with versions that have 32 bit ints. For C#, I believe the just-in-time compiler will make int 64 bits on the fly for a 64 bit CPU. For 32 bit CPUs, the size of integer will be 32 bits.
Reply:No, it depends what language you're programming in. For C# a integer is 32 bits, however in an older langauge such as VB6.0 an integer is 16 bits, and a long is 32 bits.
Reply:It's not just the language or the language version - it also depends on what compiler you are using
Reply:In C/C++ processor the int is the size of cpu arithmetic register..





in C# the int size is 32bit ..


How do I creat an integer in C++ that is a random number. Do i type int num1; //random number?

I agree with the two previous posts: use the rand() function but here's a little more info.





If you use rand() and don't seed the random number generator, your next run of your program will generate the SAME random numbers again. To fix this, use this once in your program:


srand( %26lt;some_random_value%26gt; ).





Also, if you want to determine the range of the numbers you want, then you should use the modulus operator (%). If you want the random number to be in the range of 0 to 9, then use rand()%10, if want a range of 2 to 7 use rand()%6+2.





Ex:


#include %26lt;ctime%26gt; // For time()


#include %26lt;cstdlib%26gt; // For srand() and rand()


. . .


srand(time(NULL)); // Initialize random number generator with current time as seed.


. . .


r = (rand() % 5) + 11; random number in range of 11 to 15

How do I creat an integer in C++ that is a random number. Do i type int num1; //random number?
you have to call a function called rand() it is in the math header files and modify the result to get it as far as i can tell.The math function that returns the remainder of a division works well to get the desired result. have fun.
Reply:Use then rand() function

flowering plum