- **Engineering Concepts**
(*http://www.go4expert.com/forums/engineering-concepts/*)

- - **C++ help required**
(*http://www.go4expert.com/forums/cpp-help-required-t21085/*)

C++ help requiredHi,
I am not good at programming at all and I need help with the questions below. Please help if you know how to solve them. Thankyou. Help with any of the questions is appreciated. E.1. Question 1: Program Header For this question you are asked to create a function that prints a header to the screen. This header will include your name, lab number and question number. An example of a header can be seen below.You can design your header to be unique as long as the required information is present. Program Requirements • The function you create will be required to accept two parameters: the lab number, and the question number. When you call the function, you will pass these parameters which will be displayed in the header. • Sample code is given for the ‘main’ function, which demonstrates how the function should be called. You must write the code for the function call. Sample Source Code #include <iostream> #include <string> using namespace std; void myHeader( int lab, int question); //Header function prototype int main() { myHeader( 4, 1); } // end function main // Write you code for your header function here… Sample Output ********************************* My Name Lab #4, Question #1 ********************************* Press any key to continue . . . 3 E.2. Question 2: Simulating Rolling Of Dice Using the rand function you are asked to write a program that simulates the rolling of a die a number of times and count how many times it lands on a particular side.. Program Requirements: • Use the header function created in question 1. • When your program begins it will ask the user how many times you wish to roll the die, which should be validated to be a positive number. The program will then ask which side of the die you wish to count to see how often it is rolled. Verify this number to be between 1 and 6. • Write a function that takes accepts two arguments, the number of rolls and the side of the die to count. The function should then simulate rolling the die the specified number of times and count how many times the indicated side is rolled. When completed the function will returnthe number of times the specified side was rolled. This function should use the srand and timefunctions to make the results ‘more random’ ( see lecture slides/Functions – slide 37+)• From the main function, display the results of the simulation similar to the sample output: ********************************* My Name Lab #4, Question #2 ********************************* This program uses a function that simulates rolling the dice a number of times and counting the number of times a particular side is rolled. Please enter the number of times to roll the dice: 20 Please enter which side of the dice to count (1 - 6): 4 A 4 was rolled 5 times out of 20 (25%) Press any key to continue . . . E.3. Question 3: Calculating Sine and Cosine without the CMATH Library For this question you are asked to calculate the value of the sine and cosine function without using theCMATH Library. The sine and cosine functions can be calculated (in radians) by using the following summation: Program Requirements: • Use the header function created in question 1. • Your program will begin by asking the user to enter the value of x (double), and the value of N (integer) that is used in the summation loop. The program should validate x to make sure that itis between and ( ), and also validate N to ensure it is a positive number.The program will use function-calls to calculate the value of sin(x) and cos(x), without using4 the cmath library . The results of the calculations will then be displayed using cout statements.within the main function • Your program will contain at least four functions (in addition to the header function): o Function to calculate the power function (base^exponent). This function will accepttwo parameters as arguments, the base and the exponent, and will return the result ofthe calculation. o Function to calculate the factorial function. This function will accept a double-typenumber as a parameter and calculate its factorial. The function will then return thisresult. Use double type variables to increase the range of numbers your function can represent. o Function to calculate the sine function. This function will accept a double-type number as a parameter and calculate its sine. This will be performed using the above formula and using the power and factorial functions. You cannot use cmath for this lab. o Function to calculate the cosine function. This function will accept a number as a parameter and calculate the cosine. This will be performed using the above formula and using the power and factorial functions. You cannot use cmath for this lab. o There should be no cout statements outside of the main function. |

Re: C++ help requiredThe idea of this assignment is that you learn by doing, not by posting the whole lot to a web forum and expecting someone else to do it for you. The questions are not difficult but are quite wordy so I can understand you feeling they are difficult just by their length. You can solve them just by taking them a step at a time.
Question 1. Have a look through your course notes and see if you can find (a) a function, and (b) some way to display output to the screen. You have already been given the prototype for myHeader, so how do you convert a prototype to a function? (Hint: int main() { ... } is a function that might be prototyped int main(); -- but you don't normally need to prototype main.) You have also been given the output that is wanted: a row of asterisks, your name and some other stuff. Can you think of a way to adapt the output statements you HAVE seen so that they will display this new output instead? At the very least you can have a guess at this. Post what you've got after answering this and we'll move onto the next step. It doesn't necessarily matter if what you post is wrong; we can correct it if necessary. |

All times are GMT +5.5. The time now is 12:38. |