Downloaded from
|
|
- Marcus Morris
- 6 years ago
- Views:
Transcription
1 Function: A function is a named unit of a group of statements that can be invoked from other parts of the program. The advantages of using functions are: Functions enable us to break a program down into a number of smaller and smaller and simpler units. This makes the program more organized and structured and easier to debug. It helps in reusability of code and thus reduces program size. If similar code is required at several places in the program, the use of a function allows this code to be written just once, and to be called wherever it is required. It helps to execute the same set of statements with different set of values. Function Declaration/Prototype: Just as any variable is declare before it is used in a program, it is necessary to declare a function to inform the compiler that the function would be referenced at a later point in the program. Function declaration is also called function prototype. Syntax for function declaration: <return type> <function name> ( <data type of parameter> [<parameter name>],. ); Example: int sum ( int, int); A declaration (prototype) tells the compiler that later on in our program we are going to write a particular function. It also informs the compiler about: 1. the type of result to be returned; 2. the identifier of the function; 3. the number and types of parameters; It is terminated by a semicolon. <return type>: It is the data type of the value that is returned to the calling function after the function is executed. It can be any of the data types, available in C++. <function name>: It is the name of the function, which is given with accordance to the naming conventions used for naming an identifier. A function is called with the help of it s name. <data type of parameter>: These are the data types of the parameters/inputs that the function receives when it is called. In function declaration it is optional to give the name of the parameters. The different data types specify to the compiler, the total number of parameters, and the data type of these parameters that the function will receive, when it is called (invoked). Function definition: The function definition contains the function header and the function body i.e. the set of statements which are executed when the function is called. Syntax for function definition: <return type> <function name> (<data type of parameter> <name of <parameter>,. ) Statement 1; Statement 2; : return ( value / variable / expression );
2 Example: int sum ( int a, int b) int s = a + b; return s; Note: The return statement is used to return a value to the calling function. It is always the last statement in the function definition (if the function has return type). The data type of the value returned should match with the return type of the function. // Example 1 // Program to find the factorial of a number using a function Fact () #include<conio.h> long Fact( long); // Function Prototype long num; clrscr(); cout<< \n\tenter a No. : ; cin>>num; cout<<num<<! = <<Fact(num); // Function call with num as an actual parameter getch(); // Definition of function long Fact (long N) // Function header with N as a Formal parameter long I, f=1; for( i=1; i<=n; i++) f = f * i; return f; Function Body Order of Execution in the above program main() // Execution starts from the main() Function call to Fact() // Control is passed to the function definition of Fact() Execution of the Fact() // All the statements in the function Definition of Fact() are executed Execution of statement getch() // Control returns to the main(), to the statement which follows the function call statement of Fact() Function Header: It is the first line of the function definition, which specifies the following: Return type of the function Name of the function Name of the parameters, along with their data types Note: It is not terminated with semicolon.
3 Function Body: It is the set of statements, which are executed when the function is called. Function Call: It is the statement in the calling function, through which the control is passed to the function definition of another function. This will execute the statements is the called function and then the control is returned back to the statement in the calling function, which follows the function call statement. The function call consists of the function name, followed by actual parameters, if any, enclosed in parentheses. Calling Function: The function, which calls a function is called the calling function. In the above example main() is the calling function. Called Function: The function which is called by anther function is known as the called function. Formal Parameter: The parameters mentioned in the function header are called formal parameter. Actual Parameter: Values/Variables which are used while making a call to the function are called actual parameter. Difference between call by value and call by reference Call by Reference 1) The changes made to the formal parameters are reflected back to the actual parameters. 2) It provides a mechanism of returning more than one value. 3) The reference parameters require an 3) Not Available ampersand (&) sign before their name. 4) The Formal and Actual parameters share the same memory location. 5) void Swap(int & a, int & b) int temp = a; a = b; b = temp; // Program to illustrate the invoking of a function using call by value // and call by reference methods #include<conio.h> // Function to swap the values of two variables, // where both the parameters are value parameters void swapv ( int a, int b) int temp = a; a = b; b = temp; Call by Value 1) The changes made to the formal parameters are not reflected back to the actual parameters. 2) Not Available 4) The formal and actual parameters have different memory location. 5) void Swap(int a, int b) int temp = a; a = b; b = temp; cout<< Displaying the formal parameters of swapv () function <<endl; cout<<a<< \t <<b<<endl; // Function to swap the values of two variables, // where both the parameters are variable parameters void swapr( int&b, int&b)
4 int temp = a; a = b; b = temp; cout<< Displaying the formal parameters of swapr () function <<endl; cout<<a<< \t <<b<<endl; clrscr(); int x=5, y=7; swapv(x,y); cout<< The values of actual parameters after calling the swapv() function <<endl; cout<<x<< \t <<y<<endl; swapr(x,y); cout<< The values of actual parameters after calling the swapr() function <<endl; cout<<x<< \t <<y<<endl; getch(); Returning values from Functions: When a function completes its execution it can return a single value to the calling function. // Program to explain return statement int Sum(int x, int y) int z; z = x+y; return z; clrscr(); int a,b,c; cout<< \n Enter 2 numbers : ; cin>>a>>b; OUTPUT Displaying the formal parameters of swapv() function 7 5 The values of actual parameters after calling the swapv() function 5 7 Displaying the formal parameters of swapr() function 7 5 The values of actual parameters after calling the swapr() function 7 5 OR int Sum(int x, int y) return(x+y); c = Sum(a,b); // Function call statement, the returned value is stored in the variable c cout<< \n Sum = <<c;
5 Default Parameters: A function can assign a parameter a default value. So, a function can be called with less number of parameters than that defined if values have been set. These default values are used when no value corresponding to these parameters are specified in the call to that function. The default values have to be specified in the function prototype, and not in the function definition. For example: int Change(int, int &, int c=9); The following points should be considered while using the default parameters: If a function consists of value, reference and default parameters, then the default parameters are specified in the end of the parameter list, i.e. If a parameter has a default value, then all the parameters appearing to it s right must have a default value. Reference parameter cannot have a default value. // Program to show the usage of default parameters int Calculate(int, int b=20); int x=5, y=15; cout<<calculate(x); cout<<endl; cout<<calculate(x,y); int Calculate(int a, int b) return(b/a); Difference between Local and Global Variables Local Variables Global Variables 1) They are declared outside all the functions, and can be used in all the functions after its declaration. 1) They are declared in a function, and can be used only in the function in which they are declared. 2) If a local variable has the same name as that of a global variable, then the local variable is given preference. 3) For example void Show () int m =5; // Local Variable cout<<m<<endl; 2) To access the global variable explicitly, scope resolution operator(::), is used. 3) For example int m = 50; // Global Variable void Show () int m =5; // Local Variable cout<<m<<::m<<endl; In-Built functions in Header File <math.h> Function Usage Example Result 1. fabs(x) Calculates the absolute value of the floating point number x. 2. abs(x) Calculates the absolute value of the integer x. Output 4 3 cout<<fabs(-7.5); cout<<fabs(8.25); cout<<abs(-12); cout<<abs(25); cout<<abs(-17.25); cout<<abs(25.77); 3. log(y) Calculates natural logarithm of cout<<log(100); y. cout<<log(2); 4. log10(y) Calculates the base 10 cout<<log10(100);
6 logarithm of y cout<<log10(2); pow(x, y) Calculates the power x to y. cout<<pow(10,2); cout<<pow(125,1/3.0); sqrt(x) Calculates the square root of x cout<<sqrt(25); cout<<sqrt(144); sin(x) Computes the sine of x. The angle is specified in radians. cout<<sin(90); cout<<sin(90/(22/7.0)); cos(x) Computes the cosine of x. The angle is specified in radians. cout<<cos(270); cout<<sin(90/(22/7.0)); In-Built functions in Header File <ctype.h> Function Usage Example Result 1. isalpha( x) Check if character x is A-Z or a-z char x= B ; if(isalpha(x)) Albhabet cout<< Alphabet ; cout<< Not alphabet ; 2. isdigit( x) Check if character x is 0-9 char x= 9 ; if(isdigit(x)) cout<< Digit ; cout<< Not digit ; 3. islower( x) Check if character x is lower case alphabet a-z 4. isupper( x) Check if character x is Upper case alphabet A-Z 5. Isalnum( x) Check if character x is an alphanumeric i.e. A-Z, a-z, tolower(x) Converts the character x to its lower case value i.e. if character is A-Z then it convert it to a-z. All other characters are left unchanged. It return ASCII of the lower case equivalent. 7. toupper(x) Converts the character x to its upper case value i.e. if character is a-z then it convert it to A-Z. All other characters are left unchanged. It return ASCII of the upper case char x= b ; if(islower(x)) cout<< Lowercase ; cout<< Not lowercase ; char x= B ; if(isupper(x)) cout<< Uppercase ; cout<< Not uppercase ; char x= b ; if(isalnum(x)) cout<< alphabet/digit ; cout<< other ; char x= H ; if(isupper(x)) cout<<(char)tolower(x); char x= h ; if(islower(x)) cout<<(char)toupper(x); Digit Lowercase Uppercase alphabet/ digit h H
7 equivalent. In-Built functions in Header File <conio.h> Function Usage Example Result 1. clrscr() To clear the screen clrscr(); Places the text cursor at first row, and first column on the screen 2. getch() Wait for a character input getch(); 3. gotoxy(c,r) To place the text cursor at column c and row r on the screen. gotoxy(3,6); Places the text cursor at third column and sixth row on the screen In-Built functions in Header File <stdlib.h> Function Usage Example Result 1. randomize() It is used to initialize the random number generator, so that each time a new random number is generated. randomize(); 2. random(n) It returns a random integer cout<<random(7); Will display any between 0 to n-1, both integer number inclusive. between 0-6. // Program find LCM of two number using function. int LCM( int a, int b) int i, lcm; for(i=a*b; i>=a; i--) if(i%a==0 && i%b==0) lcm=i; return lcm; int GCD(int a, int b) int i, gcd; for(i=1; i<=a; i++) if(a%i ==0 && b%i==0) gcd=i; return gcd;
8 int a, b, l,g; cout<< \n Enter 2 number : ; cin>>a>>b; l = LCM(a,b); cout<< \n LCM = <<l; g = GCD(a,b); cout<< \n GCD = <<g;
A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.
Chapter-12 FUNCTIONS Introduction A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Types of functions There are two types
More informationChapter-13 USER DEFINED FUNCTIONS
Chapter-13 USER DEFINED FUNCTIONS Definition: User-defined function is a function defined by the user to solve his/her problem. Such a function can be called (or invoked) from anywhere and any number of
More informationDownloaded from
Unit I Chapter -1 PROGRAMMING IN C++ Review: C++ covered in C++ Q1. What are the limitations of Procedural Programming? Ans. Limitation of Procedural Programming Paradigm 1. Emphasis on algorithm rather
More informationCSE202-Lec#4. CSE202 C++ Programming
CSE202-Lec#4 Functions and input/output streams @LPU CSE202 C++ Programming Outline Creating User Defined Functions Functions With Default Arguments Inline Functions @LPU CSE202 C++ Programming What is
More informationChapter 6 - Notes User-Defined Functions I
Chapter 6 - Notes User-Defined Functions I I. Standard (Predefined) Functions A. A sub-program that performs a special or specific task and is made available by pre-written libraries in header files. B.
More informationFundamentals of Computer Programming Using C
CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US01CBCA01 (Fundamentals of Computer Programming Using C) *UNIT 3 (Structured Programming, Library Functions
More informationMultiple Choice Questions ( 1 mark)
Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s
More informationC++ PROGRAMMING SKILLS Part 3 User-Defined Functions
C++ PROGRAMMING SKILLS Part 3 User-Defined Functions Introduction Function Definition Void function Global Vs Local variables Random Number Generator Recursion Function Overloading Sample Code 1 Functions
More informationFunctions. Introduction :
Functions Introduction : To develop a large program effectively, it is divided into smaller pieces or modules called as functions. A function is defined by one or more statements to perform a task. In
More informationA. Introduction to Function 1. Modular Programming input processing output functions library functions 2. Function 1. Benefit of Using Functions
Lesson Outcomes At the end of this chapter, student should be able to: Use pre-defined functions: (sqrt(), abs(), pow(), toupper(), tolower(), strcmp(), strcpy(), gets()) Build independent functions or
More informationCHAPTER 4 FUNCTIONS. 4.1 Introduction
CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main
More informationC++ Programming Lecture 11 Functions Part I
C++ Programming Lecture 11 Functions Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department Introduction Till now we have learned the basic concepts of C++. All the programs
More informationPart II Answer to all the questions (2 Marks):
Unit - III CHAPTER - 11 Functions in C++ Part 1 Choose the best answer 1. Which of the following header file defines the standard I/O predefined functions? A) stdio.h B) math.h C) string.h D) ctype.h 2.
More informationCAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE
CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE a) Mention any 4 characteristic of the object car. Ans name, colour, model number, engine state, power b) What
More informationFunctions. Lecture 6 COP 3014 Spring February 11, 2018
Functions Lecture 6 COP 3014 Spring 2018 February 11, 2018 Functions A function is a reusable portion of a program, sometimes called a procedure or subroutine. Like a mini-program (or subprogram) in its
More information3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.
1 3. Functions 1. What are the merits and demerits of modular programming? Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.
More informationCISC 1110 (CIS 1.5) Introduc2on to Programming Using C++
CISC 1110 (CIS 1.5) Introduc2on to Programming Using C++ Spring 2012 Instructor : K. Auyeung Email Address: Course Page: Class Hours: kenny@sci.brooklyn.cuny.edu hbp://www.sci.brooklyn.cuny.edu/~kenny/cisc1110
More informationb) Give the output of the following program: 6,70,70 2,70 210,282,59290
Set II 1. a) Name the header file for the following built-in functions: i) fabs() math.h ii) isalpha() ctype.h iii) toupper() ctype.h iv) cos() math.h b) Give the output of the following program: 6,70,70
More informationUnit 3 Functions. 1 What is user defined function? Explain with example. Define the syntax of function in C.
1 What is user defined function? Explain with example. Define the syntax of function in C. A function is a block of code that performs a specific task. The functions which are created by programmer are
More informationIntroduction to C++ Introduction and History. Characteristics of C++
Introduction and History Introduction to C++ Until 1980, C programming was widely popular, and slowly people started realizing the drawbacks of this language and at the same time, the engineers had come
More informationFunctions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
1 Functions Functions are everywhere in C Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Introduction Function A self-contained program segment that carries
More informationFunctions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction
Functions Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur Programming and Data Structure 1 Function Introduction A self-contained program segment that
More information& Technology. G) Functions. void. Argument2, Example: (Argument1, Syllabus for 1. 1 What. has a unique. 2) Function name. passed to.
Computer Programming and Utilization (CPU) 110003 G) Functions 1 What is user defined function? Explain with example. Define the syntax of function in C. A function is a block of code that performs a specific
More informationStrings and Library Functions
Unit 4 String String is an array of character. Strings and Library Functions A string variable is a variable declared as array of character. The general format of declaring string is: char string_name
More informationComputer Science & Engineering 150A Problem Solving Using Computers
Computer Science & Engineering 150A Problem Solving Using Computers Lecture 03 - Stephen Scott (Adapted from Christopher M. Bourke) 1 / 41 Fall 2009 Chapter 3 3.1 Building Programs from Existing Information
More informationComputer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions
Computer Science & Engineering 150A Problem Solving Using Computers Lecture 03 - Functions Stephen Scott (Adapted from Christopher M. Bourke) Fall 2009 1 / 1 cbourke@cse.unl.edu Chapter 3 3.1 Building
More informationChapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016
Chapter 6: User-Defined Functions Objectives In this chapter, you will: Learn about standard (predefined) functions Learn about user-defined functions Examine value-returning functions Construct and use
More informationANSI C Programming Simple Programs
ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double
More informationLab Instructor : Jean Lai
Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.
More informationSubject: Fundamental of Computer Programming 2068
Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find
More informationIntroduction. What is function? Multiple functions form a larger program Modular programming
FUNCTION CSC128 Introduction What is function? Module/mini program/sub-program Each function/module/sub-program performs specific task May contains its own variables/statements Can be compiled/tested independently
More informationChapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer:
Chapter-11 POINTERS Introduction: Pointers are a powerful concept in C++ and have the following advantages. i. It is possible to write efficient programs. ii. Memory is utilized properly. iii. Dynamically
More informationFunctions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single
Functions in C++ Problem-Solving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module
More information6. C++ Subprograms David Keil CS I slides 7/03 1
6. C++ Subprograms David Keil CS I slides 7/03 1 Topic: Subprograms for modularity Modular decomposition Defining C/C++ functions Local variables and scope Value parameters Reference parameters Return
More informationUNIT III (PART-II) & UNIT IV(PART-I)
UNIT III (PART-II) & UNIT IV(PART-I) Function: it is defined as self contained block of code to perform a task. Functions can be categorized to system-defined functions and user-defined functions. System
More informationIntroduction to Programming
Introduction to Programming session 9 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel s slides Sahrif University of Technology Outlines
More informationBIL 104E Introduction to Scientific and Engineering Computing. Lecture 4
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4 Introduction Divide and Conquer Construct a program from smaller pieces or components These smaller pieces are called modules Functions
More informationChapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information.
Chapter 3 Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus Lecture 03 - Introduction To Functions Christopher M. Bourke cbourke@cse.unl.edu 3.1 Building Programs from Existing
More informationKENDRIYA VIDYALAYA SANGATHAN, GUWAHATI REGION HALF-YEARLY EXAMINATION-2015 CLASS XI : COMPUTER SCIENCE Time Allotted : 3 hrs. Max.
KENDRIYA VIDYALAYA SANGATHAN, GUWAHATI REGION HALF-YEARLY EXAMINATION-2015 CLASS XI : COMPUTER SCIENCE Time Allotted : 3 hrs. Max. Marks : 70 Q.1..... operator in C++, requires three operands. [1] Q.2
More informationINTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from
INTRODUCTION TO C++ FUNCTIONS Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Functions: Program modules in C Function Definitions Function
More informationFunction. specific, well-defined task. whenever it is called or invoked. A function to add two numbers A function to find the largest of n numbers
Functions 1 Function n A program segment that carries out some specific, well-defined task n Example A function to add two numbers A function to find the largest of n numbers n A function will carry out
More informationUEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter
UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter What you will learn from Lab 7 In this laboratory, you will understand how to use typical function prototype with
More informationGE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004
GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout
More informationC++ Programming: Functions
C++ Programming: Functions Domingos Begalli Saddleback College, Computer Science CS1B, Spring 2018 1 / Domingos Begalli CS1B Sprint 2018 C++ Introduction 1/22 22 we will cover predefined functions user-defined
More information6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x
(Function) -1.1 Math Library Function!"#! $%&!'(#) preprocessor directive #include !*+!"#!, Function Description Example sqrt(x) square root of x sqrt(900.0) is 30.0 sqrt(9.0) is 3.0 exp(x) log(x)
More informationLaboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++
Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ 0.1 Introduction This is a session to familiarize working with the Visual Studio development environment. It
More informationEngineering Problem Solving with C++, Etter/Ingber
Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input
More informationWT I (SET-I) Date: Class XI Sec. Time: 1 Hr. 10 min. Computer Science M.M.: 30
WT I (SET-I) Date: Class XI Sec. Time: 1 Hr. 10 min. Computer Science M.M.: 30 Name Roll No. Instructions: a) All questions are compulsory. b) There are 15 questions in this paper and each question carries
More informationDELHI PUBLIC SCHOOL TAPI
Loops Chapter-1 There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed
More informationC Functions. 5.2 Program Modules in C
1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking
More informationVOLUME II CHAPTER 9 INTRODUCTION TO C++ HANDS ON PRACTICE PROGRAMS
VOLUME II CHAPTER 9 INTRODUCTION TO C++ HANDS ON PRACTICE PROGRAMS 1. Write C++ programs to interchange the values of two variables. a. Using with third variable int n1, n2, temp; cout
More informationBITG 1113: Function (Part 2) LECTURE 5
BITG 1113: Function (Part 2) LECTURE 5 1 Learning Outcomes At the end of this lecture, you should be able to: explain parameter passing in programs using: Pass by Value and Pass by Reference. use reference
More informationAIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session ) Contents
AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session- 2017-18) Month July Contents UNIT 1: COMPUTER FUNDAMENTALS Evolution of computers; Basics of computer and its operation;
More informationvinodsrivastava.wordpress.com Question Bank Term-1
vinodsrivastava.wordpress.com Question Bank Term-1 Q1 Write Header File for following Function/object Function/object presents in header file cin, cout, endl, gets(), puts(), M_PI, abs(), labs(), fabs(),
More informationEECS402 Lecture 02. Functions. Function Prototype
The University Of Michigan Lecture 02 Andrew M. Morgan Savitch Ch. 3-4 Functions Value and Reference Parameters Andrew M. Morgan 1 Functions Allows for modular programming Write the function once, call
More informationIt is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.
Functions A number of statements grouped into a single logical unit are called a function. The use of function makes programming easier since repeated statements can be grouped into functions. Splitting
More informationTechnical Questions. Q 1) What are the key features in C programming language?
Technical Questions Q 1) What are the key features in C programming language? Portability Platform independent language. Modularity Possibility to break down large programs into small modules. Flexibility
More informationIntroduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation
Introduction to Algorithms and Data Structures Lecture 6 - Stringing Along - Character and String Manipulation What are Strings? Character data is stored as a numeric code that represents that particular
More informationBasic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces
Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program
More informationC++, How to Program. Spring 2016 CISC1600 Yanjun Li 1
Chapter 6 Function C++, How to Program Deitel & Deitel Spring 2016 CISC1600 Yanjun Li 1 Function A function is a collection of statements that performs a specific task - a single, well-defined task. Divide
More informationComputer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries
Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries Hazırlayan Asst. Prof. Dr. Tansu Filik Computer Programming Previously on Bil 200 Low-Level I/O getchar, putchar,
More informationBasic Source Character Set for C++ Language:
Lecture 4 1. Programming in C++ Language: C++ was created by Bjarne Stroustrup, beginning in 1979. The development and refinement of C++ was a major effort, spanning the 1980s and most of the 1990s. Finally,
More informationLesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University
Lesson #3 Variables, Operators, and Expressions Variables We already know the three main types of variables in C: int, char, and double. There is also the float type which is similar to double with only
More informationChapter 2. Outline. Simple C++ Programs
Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.
More informationm) sin() n) endl o) getch() p) cout
SAMPLE PAPER 1. a) Name the header file for the following built-in functions: a) log() b) exp() c) getch() d) isalnum() e) fabs() f) isalpha() g) toupper() h) cos() i) random() j) gets() k) abs() l) tolower()
More informationC++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 6: User-Defined Functions I In this chapter, you will: Objectives Learn about standard (predefined) functions and discover
More informationCreating a C++ Program
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an
More informationIntroduction to Functions in C. Dr. Ahmed Telba King Saud University College of Engineering Electrical Engineering Department
Introduction to Functions in C Dr. Ahmed Telba King Saud University College of Engineering Electrical Engineering Department Function definition For example Pythagoras(x,y,z) double x,y,z; { double d;
More informationChapter 1. Computer Overview
DELHI PUBLIC SCHOOL, Durgapur QUESTION BANK of computer science FOR block test-i examination (2018-19) CLASS-XI Chapter 1. Computer Overview 1. What is data? What is information? 2. Name the subunits of
More informationComputer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore
Sir Syed University of Engineering and Technology. Computer ming & Problem Solving ( CPPS ) Functions Chapter No 1 Compiled By: Sir Syed University of Engineering & Technology Computer Engineering Department
More informationADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1
NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.
More informationDr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)
Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly
More informationLecture 2:- Functions. Introduction
Lecture 2:- Functions Introduction A function groups a number of program statements into a unit and gives it a name. This unit can then be invoked from other parts of the program. The most important reason
More informationFunctions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.
Lab 4 Functions Introduction: A function : is a collection of statements that are grouped together to perform an operation. The following is its format: type name ( parameter1, parameter2,...) { statements
More informationAMCAT Automata Coding Sample Questions And Answers
1) Find the syntax error in the below code without modifying the logic. #include int main() float x = 1.1; switch (x) case 1: printf( Choice is 1 ); default: printf( Invalid choice ); return
More informationFORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):
FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The basic commands that a computer performs are input (get data), output (display result),
More information5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!
FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. Assume that all variables are properly declared. The following for loop executes 20 times.
More informationChapter 3 - Functions
Chapter 3 - Functions 1 Outline 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number
More informationSample Paper Class XI Subject Computer Sience UNIT TEST II
Sample Paper Class XI Subject Computer Sience UNIT TEST II (General OOP concept, Getting Started With C++, Data Handling and Programming Paradigm) TIME: 1.30 Hrs Max Marks: 40 ALL QUESTIONS ARE COMPULSURY.
More informationThe University Of Michigan. EECS402 Lecture 02. Andrew M. Morgan. Savitch Ch. 3-4 Functions Value and Reference Parameters.
The University Of Michigan Lecture 02 Andrew M. Morgan Savitch Ch. 3-4 Functions Value and Reference Parameters Andrew M. Morgan 1 Functions Allows for modular programming Write the function once, call
More informationCS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their
More informationUNIT - I. Introduction to C Programming. BY A. Vijay Bharath
UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been
More informationcs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).
cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion
More informationOBJECTIVE QUESTIONS: Choose the correct alternative:
OBJECTIVE QUESTIONS: Choose the correct alternative: 1. Function is data type a) Primary b) user defined c) derived d) none 2. The declaration of function is called a) function prototype b) function call
More informationI Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.
I Internal Examination Sept. 2018 Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. [I]Very short answer questions (Max 40 words). (5 * 2 = 10) 1. What is
More informationLecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR
1 Statements: A statement in a computer carries out some action. There are three types of statements used in C++; they are expression statement, compound statement and control statement. Expression statement
More informationOutline. Functions. Functions. Predefined Functions. Example. Example. Predefined functions User-defined functions Actual parameters Formal parameters
Outline Functions Predefined functions User-defined functions Actual parameters Formal parameters Value parameters Variable parameters Functions 1 Functions 2 Functions Predefined Functions In C++ there
More informationFunctions. Arash Rafiey. September 26, 2017
September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic
More informationFaculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions
Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2013 C++ Programming Language Lab # 6 Functions C++ Programming Language Lab # 6 Functions Objective: To be familiar with
More informationUnit 7. Functions. Need of User Defined Functions
Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have
More informationtoday cs3157-fall2002-sklar-lect05 1
today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical
More informationDarshan Institute of Engineering & Technology for Diploma Studies
1. Explain Call by Value vs. Call by Reference Or Write a program to interchange (swap) value of two variables. Call By Value In call by value pass value, when we call the function. And copy this value
More informationVariable x is created and assigned a value 35. Variable is y created as a copy of x. Variables x and y are two separate memory locations.
Reference (Alias) Normally when ever we create a variable in C++ program, a new memory location is created and some value is stored in that memory location. An example is given below int x=35; int y=x;
More informationFUNCTIONS OMPAL SINGH
FUNCTIONS 1 INTRODUCTION C enables its programmers to break up a program into segments commonly known as functions, each of which can be written more or less independently of the others. Every function
More informationCS201- Introduction to Programming Current Quizzes
CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements
More informationPROGRAMMING IN C++ COURSE CONTENT
PROGRAMMING IN C++ 1 COURSE CONTENT UNIT I PRINCIPLES OF OBJECT ORIENTED PROGRAMMING 2 1.1 Procedure oriented Programming 1.2 Object oriented programming paradigm 1.3 Basic concepts of Object Oriented
More informationChapter 6: Functions
Chapter 6: Functions 6.1 Modular Programming Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules Function: a collection of statements to perform
More informationProgramming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1
300580 Programming Fundamentals 3 With C++ Variable Declaration, Evaluation and Assignment 1 Today s Topics Variable declaration Assignment to variables Typecasting Counting Mathematical functions Keyboard
More informationMethods CSC 121 Fall 2016 Howard Rosenthal
Methods CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand what a method is in Java Understand Java s Math Class and how to use it Learn the syntax of method construction Learn both void methods
More information6.1. Chapter 6: What Is A Function? Why Functions? Introduction to Functions
Chapter 6: 6.1 Functions Introduction to Functions What Is A Function? Why Functions? We ve been using functions ( e.g. main() ). C++ program consists of one or more functions Function: a collection of
More information