Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //function :- DRY (donot repeat yourself)
- // we can modularize the program using the function
- // seperate the cde into logical self-contained units
- //These units are reusable
- //c++ program:
- //c++ standared templete library(STL)(ie.vector ,isostream)
- //third party library(coco2dx,unreal,spring,cry engine)
- //self created or our own function
- //(dont reinvent the wheel)
- // Abstraction in oop
- //function defination(user define function)
- // function type function name(parameters){
- //statements(body of the function)
- //return type
- //}
- // name :-same rule as variables it should br meaningful
- // parameter list:-the variable passed into the function -their type must be specified
- //return tupe - type pf the data is returned by the function.
- //body:-statements that are executed when the function is called - it lies within the scope
- /*#include<iostream>
- using namespace std;
- void hello(){
- cout<<"hello";
- }
- void world(char name[]){
- hello();
- cout<<"world"<<name<<endl;
- }
- int main(){
- world("rupesh");
- return 0;
- }
- */
- /*
- #include<iostream>
- using namespace std;
- const double pi=(3.14159);
- double calc_area_circle(double radius ){
- return pi*radius*radius ;
- }
- double calc_area_cylinder(double radius,double height){
- return pi*radius*height;
- }
- void area_circle(){
- double radius={0};// c++ standared brace initialization double radius{0}
- cout<<"enter the radius of the circle";
- cin>>radius;
- cout<<"The area of the circle is "<<calc_area_circle(radius);
- }
- void area_cylinder(){
- double radius={0};
- double height ={0};// c++ STANDARED copy-brace initialization double radius={0}
- cout<<"Enter the radius of the cylinder";
- cin>>radius;
- cout<<"Enter the height of the cylinder";
- cin>>height;
- cout<<"the area of the cylinder is "<<calc_area_cylinder(radius,height);
- }
- int main(){
- area_cylinder();
- area_circle();
- }
- */
- //function prototype:
- //-It tells the compiler about the function befor it is used .
- //-Also called as forward declaration
- //-paced at the top of the beginning of the program
- //function prototypes
- /*double calc_area_circle(double radius);
- double calc_area_cylinder(doube radius,double height);
- void area_circle();
- void area_cylinder();
- int main(){}
- declaration of the functions
- //function parameters:
- * when we call a function we pass in data to the function
- * In function call they are called Actual Parameters .(arguments )
- *In function defination they are called Formal parameters.(parameters)
- *int add(int a, int b)//prototype
- *int main(){
- * int x={1};
- * int y={4};
- * add(x,y); // actual parameter }
- * int addition(int a., int b){ // formal parameter
- * return a+b;}
- //pass_by_value:
- * when you pass a data into a function it is called pass-by-value
- * A copy of the data is passed into the function.
- * whatever changes you make to the parameters in the function dosent affedt the argument that was passed in.
- * what happens in a function stays in the function
- *
- *
- //return statement
- //Defult parameters value
- //Overloading
- //passing array to the function
- //pass_by_refernce
- //infinite function
- //Auto return type
- //Return reference
- */
- //assinmet 2:
- // conditional statement(if else ,nested if..else case ...break)
- // looping satements(for loop,while looop, do..while loop,nested loop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement