Advertisement
rex9840

Untitled

Sep 28th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. //function :- DRY (donot repeat yourself)
  2. // we can modularize the program using the function
  3. // seperate the cde into logical self-contained units
  4. //These units are reusable
  5. //c++ program:
  6. //c++ standared templete library(STL)(ie.vector ,isostream)
  7. //third party library(coco2dx,unreal,spring,cry engine)
  8. //self created or our own function
  9. //(dont reinvent the wheel)
  10. // Abstraction in oop
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. //function defination(user define function)
  20. // function type function name(parameters){
  21. //statements(body of the function)
  22. //return type
  23. //}
  24. // name :-same rule as variables it should br meaningful
  25. // parameter list:-the variable passed into the function -their type must be specified
  26. //return tupe - type pf the data is returned by the function.
  27. //body:-statements that are executed when the function is called - it lies within the scope
  28.  
  29. /*#include<iostream>
  30. using namespace std;
  31. void hello(){
  32. cout<<"hello";
  33. }
  34. void world(char name[]){
  35. hello();
  36. cout<<"world"<<name<<endl;
  37. }
  38. int main(){
  39. world("rupesh");
  40. return 0;
  41. }
  42.  
  43. */
  44.  
  45.  
  46. /*
  47. #include<iostream>
  48. using namespace std;
  49. const double pi=(3.14159);
  50. double calc_area_circle(double radius ){
  51. return pi*radius*radius ;
  52. }
  53. double calc_area_cylinder(double radius,double height){
  54. return pi*radius*height;
  55. }
  56. void area_circle(){
  57. double radius={0};// c++ standared brace initialization double radius{0}
  58. cout<<"enter the radius of the circle";
  59. cin>>radius;
  60. cout<<"The area of the circle is "<<calc_area_circle(radius);
  61. }
  62. void area_cylinder(){
  63. double radius={0};
  64. double height ={0};// c++ STANDARED copy-brace initialization double radius={0}
  65. cout<<"Enter the radius of the cylinder";
  66. cin>>radius;
  67. cout<<"Enter the height of the cylinder";
  68. cin>>height;
  69. cout<<"the area of the cylinder is "<<calc_area_cylinder(radius,height);
  70. }
  71. int main(){
  72. area_cylinder();
  73. area_circle();
  74. }
  75.  
  76. */
  77. //function prototype:
  78. //-It tells the compiler about the function befor it is used .
  79. //-Also called as forward declaration
  80. //-paced at the top of the beginning of the program
  81.  
  82.  
  83.  
  84.  
  85. //function prototypes
  86. /*double calc_area_circle(double radius);
  87. double calc_area_cylinder(doube radius,double height);
  88. void area_circle();
  89. void area_cylinder();
  90. int main(){}
  91. declaration of the functions
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. //function parameters:
  101. * when we call a function we pass in data to the function
  102. * In function call they are called Actual Parameters .(arguments )
  103. *In function defination they are called Formal parameters.(parameters)
  104. *int add(int a, int b)//prototype
  105. *int main(){
  106. * int x={1};
  107. * int y={4};
  108. * add(x,y); // actual parameter }
  109. * int addition(int a., int b){ // formal parameter
  110. * return a+b;}
  111. //pass_by_value:
  112. * when you pass a data into a function it is called pass-by-value
  113. * A copy of the data is passed into the function.
  114. * whatever changes you make to the parameters in the function dosent affedt the argument that was passed in.
  115. * what happens in a function stays in the function
  116. *
  117. *
  118.  
  119. //return statement
  120. //Defult parameters value
  121. //Overloading
  122. //passing array to the function
  123. //pass_by_refernce
  124. //infinite function
  125. //Auto return type
  126. //Return reference
  127. */
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140. //assinmet 2:
  141. // conditional statement(if else ,nested if..else case ...break)
  142. // looping satements(for loop,while looop, do..while loop,nested loop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement