Stats: 3,191,953 members, 7,946,136 topics. Date: Wednesday, 11 September 2024 at 01:05 PM |
Nairaland Forum / Science/Technology / Programming / Help Needed With The Following Questions In C++ Or Any Language Please!!! (1688 Views)
Whatsapp Group Chat For C# &/or C++ / Creating UWP Application In C# Or C++ (xaml) / C Or C++, Which Is Best For Arduino Programming? (2) (3) (4)
Help Needed With The Following Questions In C++ Or Any Language Please!!! by Iyalodeofcanada: 4:21am On Jan 15, 2016 |
Please help a beginner Question 1. Write a function that takes three integers as arguments and returns the product of the largest two. #include<iostream> int maxmul(int a, int b, int c) { } int main() { cout << maxmul(1,2,3) << endl; cout << maxmul(3,1,2) << endl; cout << maxmul(3,2,1) << endl; } Question 2. Write a function, inc, that increases the value of variable x by 1.0; #include<iostream> int main() { float x=10.0; cout << inc(x) << endl; } Question 3. Write a function that calculates and returns the average value of an array of doubles. The length of the array is provided as a second argument, n. double average_array(double data[], int n) { } Question 4. Write a function to subtract the average value of the entire array from each array element. You may make use of the average_array function from the first question. void subtract_average(double data[], int n) { } Question 5. Write a function to calculate the average value of a 100 by 100 array of ints. Return the average as a double. question 6. Write a program to dynamically allocate a n by m array of doubles. Both n and m should be read from the console. All elements of the array should be initialized to zero. All memory should be freed before the program exits. Question 7. The function trap() numerically integrates exp(x^2) in the interval x=[a,b]. n is the number of points to evaluate the function at. Add comments to the function and format it using C++ standards. #include<cmath> float exp_mx2(int x) {return(exp(x*x));} float trap(float a, float b, int n) { float h = (ba)/(n1); float value = 0.5*( f(a)+ f(b)); for(int k=2; k < n; k++){value+=f( a + h*(k1)); } value*=h;return(value); } |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Otuabaroku: 6:39am On Jan 15, 2016 |
@Op, I think this is an assignment given to you to do. It makes sense for you to make an attempt. When people see your effort, then you can be helped. In that way,you learn more from the assignment. 3 Likes |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Nobody: 6:59pm On Jan 15, 2016 |
solution 1 #include <iostream> using namespace std; int main ( ) { int maximum (int a, inb,intc) { int a =1; int b=2; int b=3; product =inta*intb cout <<product<< endl; return 0 } |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Nobody: 7:05pm On Jan 15, 2016 |
solution2 #include <iostream> using namespace std; int main ( ) { int x=10 ; ++x; for (inti=0;i <10;++i); cout <<++x<<endl; return 0; } |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Nobody: 7:13pm On Jan 15, 2016 |
solution 3 #include <iostream> Using namespace std; int main ( ) { double data [] = {a,b} ; cout <<"Enter two numbers :add\n"; cin>>a>>b; average =(a+b)*2 cout <<average<< endl; return 0 ; } |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Nobody: 7:21pm On Jan 15, 2016 |
solution 5 #include <iostream> Using namespace std; int main ( ) { int array [] ={100,100} ; // calculate the Average int sum =0 ; for (inti=0;i <numbers.length; i++) ; double average =sum /numbers.length; cout <<average <<endl ; return 0 ; } |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Nobody: 7:27pm On Jan 15, 2016 |
solution 6 #include <iostream> Using namespace std; int main ( ) { array double [] = {m,n} =0 cin>>m>>n; std:cout <<array double << std ::endl; delete [] array ; return 0 ; } |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Nobody: 7:35pm On Jan 15, 2016 |
solution 7 is pending
TheTrapezoidal Rule |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Iyalodeofcanada: 11:15pm On Jan 15, 2016 |
Otuabaroku: I was able to come about this for number 1 int maxmul(int a, int b, int c) { int min; min = a; if b<min min = b; if c<min min = c; return a*b*c/min; } Question 2 double inc(double x) { return x+1.0; |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Iyalodeofcanada: 11:17pm On Jan 15, 2016 |
proxy20: I am very grateful thank you alot!............Please teach me! I really want to learn!! |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Iyalodeofcanada: 11:22pm On Jan 15, 2016 |
proxy20: As regards your solutions, can i present the first like this? #include<iostream> int maxmul(int a, int b, int c) { } int main() { int a =1; int b=2; int b=3; product =inta*intb cout <<product<< endl; return 0 } cout << maxmul(1,2,3) << endl; cout << maxmul(3,1,2) << endl; cout << maxmul(3,2,1) << endl; } |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Nobody: 11:24pm On Jan 15, 2016 |
check Google or your math textbook. is it a school assignment. |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Otuabaroku: 5:54am On Jan 16, 2016 |
Iyalodeofcanada: @Iyalodeofcanada let me put you through to number 1 and 5, with that you can try the rest. Question 1. Write a function that takes three integers as arguments and returns the product of the largest two. Here you are required to find the largest two of the three numbers entered by the user. In my solution, I have decided to store the data entered by the user in array and subsequently sort them in ascending order. With this sorting, I now know that the last two are the largest two of the three numbers entered by the user; hence, simply multiplying the two, will give me the answer.Here is code blow.
|
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Otuabaroku: 6:26am On Jan 16, 2016 |
For solution 5. Question 5. Write a function to calculate the average value of a 100 by 100 array of ints. Return the average as a double.
Hope this helps to try the others. |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Nobody: 9:59am On Jan 16, 2016 |
You can convert this bunch of programs to a native android app using Android ndk and studio or eclipse with adt bundle ,sdk and ndk to cool apps . NDK is for native apps development in c/c++ . create the java class , and c/c++ class and android Xml and build. |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Iyalodeofcanada: 5:42pm On Jan 16, 2016 |
Otuabaroku: Thank you for this but your code seems too advanced for a baby programmer like me(I started this class one week ago). I have been googling each line all day. The truth is it is an assignment due tommorow. It is not as if i am been lazy but right now i just have to deliver and i am looking for the simplest way to go about this later i can now read up and catch up on array declarations and all that. Still working on it though thanks alot #include <iostream> using namespace std; int maxmul(int a, int b, int c) { int min; int a = 1; int b = 2; int c = 3; } int main() if b < min min = b; if c < min min = c; { cout << maxmul(1,2,3) << endl; cout << maxmul(3,1,2) << endl; cout << maxmul(3,2,1) << endl; } return a*b*c/min; |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Nobody: 5:48pm On Jan 16, 2016 |
Which compiler are u using? |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by DonSegmond(m): 6:03pm On Jan 16, 2016 |
I decided to implement a few of these using clojure. I like clojure, because it's a lisp that runs on java. by being a lisp, you can develop functional programs that are very small, easy to test and fast. the code below took about 5 minutes to write.
Results 70 8.0 11/2 (-9/2 -7/2 -5/2 -3/2 -1/2 1/2 3/2 5/2 7/2 9/2) |
Re: Help Needed With The Following Questions In C++ Or Any Language Please!!! by Iyalodeofcanada: 6:05pm On Jan 16, 2016 |
Visual studio c++ 2011. proxy20: |
(1) (Reply)
Can You Solve This? / Which Website Do You Download Your Ebooks From ? / SHA1 Function Is Now Dead
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 38 |