# question 3 - Fundamentals Programming Functions Laboratory...

• Test Prep
• 2

This preview shows pages 1–2. Sign up to view the full content.

Fundamentals Programming Functions Laboratory 3 1. Analyze the following program: #include <iostream> using namespace std; float absolute(float x); int main () { float num, answer; cout << "Enter an integer (0 to stop): "; cin >> num; while (num!=0){ answer = absolute(num); cout << "The absolute value of " << num << " is: " << answer << endl; cin>>num; } return 0; } // Define a function to take absolute value of an integer float absolute(float x) { if (x >= 0) return x; else return -x; } 2. Complete the function below to compute the square root of a number. Use a function absolute. To float squere_root(float x) { float epsilon = 0.000001; float quess = 1.01; while( (quess*quess-x) > = epsilon) { quess=(x/quess + quess)/2.0; } return quess; } 3. Write a function in C++ that display n times your name, where n is a function parameter. 4. Write a function in C++ that find the maximum of three floating-point numbers. 5. Write a function in C++ that counts the number of zeros elements in an array. An array and the number of element in array are parameters of the function. The function returns integer

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: value as a number of elements equal zero. Barbara Fryc Fundamentals Programming Functions Laboratory 3 6. Analyze the following program. void fun(char tab); void fun_ pointers (char *w) ; /*******************************************************/ main() { char arr[80] = {"learn more about programming in C++" } ; cout << "\n version nr 1 \n" ; fun (arr); // cout << "\n version nr 2 \n" ; fun_pointers(arr); // } /******************************************************/ void fun(char tab) // { int i = 0 ; while(tab[i]) { cout << tab[i++] << "-" ; } } /*******************************************************/ void fun_pointers (char *w) { while(*w) { cout << *(w++) << "-" ; } } /****************************************************/ 7. Write a function in C++ that counts the number of elements in an char array. An array is a parameter of the function. The function returns int value as a number of elements in an array. Barbara Fryc...
View Full Document

• Spring '15
• #include, Barbara Fryc

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern