The following function receives an input from the calling function and returns

The following function receives an input from the

This preview shows page 12 - 16 out of 26 pages.

// The following function receives an input from the calling function and // returns the square of the number to the calling function. // extern double square( double x) // function square() is defined { return ( x * x ); // note the RETURN (x * x) } Solution:- Please input three double numbers here ==> 5.23 4.12 3.36 Iteration Value of i Function_i = a*(i*i)+b*i+c _________ __________ _____________________________ 1 0.00 3.36 2 0.50 6.73 3 1.00 12.71 4 1.50 21.31 5 2.00 32.52 6 2.50 46.35 7 3.00 62.79 8 3.50 81.85 9 4.00 103.52 10 4.50 127.81 11 5.00 154.71 12 5.50 184.23 13 6.00 216.36 14 6.50 251.11 15 7.00 288.47 16 7.50 328.45 17 8.00 371.04 Press any key to continue . . . 12
Image of page 12
// File Name ................. SP6_5.CPP // Course .................... ELET 2300 Introduction to C++ Programming // Programmer ................ Dr. Farrokh Attarzadeh // Compiler .................. Microsoft Visual Studio 2010 .NET // Operating System .......... Windows Vista // Environment ............... Console Applications // Copyright ................. © 2013 Dr. Farrokh Attarzadeh // Date ...................... 01/01/2013 // // Program Description // ___________________ // // This program uses some built-in math functions in cmath to calculate the // sine, cosine, and the tangent of the input parameter. Since the input to // these trig functions is in radians, the program computes the equivalent // angles in degrees and displays them. // Include files used #include <cmath> // for math functions #include <iostream> #include <iomanip> #include <cstdlib> using namespace std; int main( void ) { int j = 0; // local variable const double R_TO_D = 180.0 / 3.1415; // rad to deg conversion double i, degrees ; // set parameters for data display cout.setf(ios::showpoint); cout.precision(2); cout.setf(ios::fixed, ios::floatfield); cout << "\t\tIteration\tRadians\tDegrees\t Sine\tCosine\tTangent\n" ; cout << "\t\t_________\t_______\t_______\t ____\t______\t_______\n\n" ; for (i = 0.0; i <= 8.0; i += 0.5) { j++; degrees = R_TO_D * i; cout << "\t\t" << setw(5) << j << "\t\t" << i << '\t' << degrees << "\t\t" << sin(i) << '\t' << cos(i) << '\t' << tan(i) << "\n\n" ; } return EXIT_SUCCESS; } 13
Image of page 13
Solution:- Iteration Radians Degrees Sine Cosine Tangent _________ _______ _______ ____ ______ _______ 1 0.00 0.00 0.00 1.00 0.00 2 0.50 28.65 0.48 0.88 0.55 3 1.00 57.30 0.84 0.54 1.56 4 1.50 85.95 1.00 0.07 14.10 5 2.00 114.59 0.91 -0.42 -2.19 6 2.50 143.24 0.60 -0.80 -0.75 7 3.00 171.89 0.14 -0.99 -0.14 8 3.50 200.54 -0.35 -0.94 0.37 9 4.00 229.19 -0.76 -0.65 1.16 10 4.50 257.84 -0.98 -0.21 4.64 11 5.00 286.49 -0.96 0.28 -3.38 12 5.50 315.14 -0.71 0.71 -1.00 13 6.00 343.78 -0.28 0.96 -0.29 14 6.50 372.43 0.22 0.98 0.22 15 7.00 401.08 0.66 0.75 0.87 16 7.50 429.73 0.94 0.35 2.71 17 8.00 458.38 0.99 -0.15 -6.80 Press any key to continue . . . 14
Image of page 14
// File Name ................. SP6_6.CPP // Course .................... ELET 2300 Introduction to C++ Programming // Programmer ................ Dr. Farrokh Attarzadeh // Compiler .................. Microsoft Visual Studio 2010 .NET // Operating System .......... Windows Vista // Environment ............... Console Applications // Copyright ................. © 2013 Dr. Farrokh Attarzadeh // Date ...................... 01/01/2013 // Program Description // ___________________ // // Develop a C++ program that prompts the user for two integers and one of // letter codes a, s, m, or q. The interpretation is given by the following // table: // Letter Meaning // _____________________ // a Add // s Subtract // m Multiply // q Quit // // The function main() issues the prompt and stores the user's input in the // variables d1, d2, and op. Then main() checks the letter code. If // the letter code is a, main() will invoke the function add() with arguments // d1 and d2 and similarly for s and m. Each of the functions add(), // subtract(), and multiply() invokes the function result(), which prints the // result of the arithmetic operation. Option q terminates the program. // Full function prototyping is used in this example. Parameter passing // convention is by value.
Image of page 15
Image of page 16

You've reached the end of your free preview.

Want to read all 26 pages?

  • Fall '15
  • Marinolent

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture