tailieunhanh - A Complete Guide to Programming in C++ part 27
A Complete Guide to Programming in C++ part 27. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | SOLUTIONS 239 Function circle Compute circumference and area. void circle const double r double u double f const double pi u 2 pi r f pi r r Exercise 3 ------------------------------------------------------ Definition and call of the function swap . 1. version parameters with pointer type 2. version parameters with reference type. ------------------------------------------------------ include iostream using namespace std void swap float float Prototypes of swap void swap float float int main float x float y cout x and y before swapping x y endl swap x y Call pointer version. cout x and y after 1. swapping x y endl swap x y Call reference version. cout x and y after 2. swapping x y endl return 0 void swap float p1 float p2 Pointer version float temp Temporary variable temp p1 Above call points p1 p1 p2 to x and p2 to y. p2 temp 240 CHAPTER 12 REFERENCES AND POINTERS void swap float a float b Reference version float temp Temporary variable temp a For above call a b a equals x and b equals y b temp Exercise 4 ------------------------------------------------------ Defines and calls the function quadEquation which computes the solutions of quadratic equations a x x b x c 0 The equation and its solutions are printed by the function printQuadEquation . ------------------------------------------------------ include include include include using namespace std iostream iomanip string cmath For the square root sqrt string header Solutions of Quadratic Equations n line 50 - ------ Prototypes-------- Computing solutions bool quadEquation double a double b double c double xlPtr double x2Ptr Printing the equation and its solutions void printQuadEquation double a double b double c int main cout header endl printQuadEquation printQuadEquation printQuadEquation return 0 SOLUTIONS 241 Prints the equation and its solutions void printQuadEquation double a double b double c double xl x2 For .
đang nạp các trang xem trước