Functions. If the inline function is called frequently, the size of the executable file increases and requires more memory.
|
|
|
- Shanna Brown
- 9 years ago
- Views:
Transcription
1 Inline functions Functions Member functions can be defined either inside or outside the class definition.a member function defined inside the class is called as an inline function. Inline functions are defined inside the class before other functions of that class. The definition of inline functions begin with the keyword inline. Inline functions are small and simple. The compiler replaces the function call statement with the actual code. Inline function run faster than normal functions. Function defined outside the class can be made inline including the keyword inline Advantages Inline functions are small in size and compact. Inline functions are executed faster than other functions. Efficient code can be generated. Readability of the program is increased. Disadvantage: If the inline function is called frequently, the size of the executable file increases and requires more memory. Note:Inline functions do not work if: the definition is long and complicated. function code contains looping statements, switch or goto statements. there are recursive calls Square of 5 = 25 inlineint square(int x) Square of 10 = 100 return(x*x); Square of 15 = 225 Square of 20 = 400 cout<<"square of 5 = "<<square(5)<<endl; cout<<"square of 10 = "<<square(10)<<endl; cout<<"square of 15 = "<<square(15)<<endl; cout<<"square of 20 = "<<square(20)<<endl; Program to find the cube of a number using inline function inlineint cube(int x) return(x*x*x); int n; cout<<"enter the number: "; cin>>n; cout<<"cube of "<<n<<" = "<<cube(n); Enter the number: 10 Cube of 10 = 1000 Enter the number: -5 Cube of -5 = -125
2 To convert the temperature from Celsius to Fahrenheit using inline function (F=C*1.8+32) inline float ctof(float c) return(c*1.8+32); floatcelsius; cout<<"enter the temperature in Celsius: "; cin>>celsius; cout<<celsius<<"c = "<<ctof(celsius)<<"f"; To convert the distance in kilometers to miles using inline function (1KM = miles) inline float ctof(float c) return(c*1.8+32); inline float kmtom(float k) return(k* ); floatcelsius; float kms; Friend functions cout<<"enter the temperature in Celsius: "; cin>>celsius; cout<<celsius<<"c = "<<ctof(celsius)<<"f"<<endl; cout<<"enter the distance in kilometers: "; cin>>kms; cout<<kms<<"kms = "<<kmtom(kms)<<"miles"; We have seen that private and protected members of a class cannot be accessed from outside the class in which they are declared. In other words, non-member function does not have access to the private data members of a class. But there could be a situation where two classes must share a common function. C++ allows the common function to be shared between the two classes by making the common function as a friend to both the classes, thereby allowing the function to have access to the private data of both of these classes. A friend function is a non-member function that is a friend of a class. The friend function is declared within a class with the prefix friend.but it should be defined outside the class like a normal function without the prefix friend. It can access public members like non-member functions. Syntax: class class_name friend void function1(void); ; Enter the temparature in Celcius: 27 27C = 80.6F Enter the temperature in Celsius: 27 27C = 80.6F Enter the distance in kilometers: kms = miles
3 Example 8.3: class base nt val1, val2; voidgetdata() cout<< Enter two values: ; cin>>val1>>val2; friend float mean(base ob); ; float mean(base ob) return float(ob.val1+ob.val2)/2; In the above example,mean() is declared as friend function that computes mean value of two numbers input using getdata() function. A friend function although not a member function, has full access right to the private and protected members of the class. A friend function cannot be called using the object of that class. It can be invoked like any normal function. friend function is declared by the class that is granting access. The frienddeclaration can be placed anywhere inside the class definition. It is not affected by the access specifiers (public, private and protected.) Friend functions are normal external functions that are given special access privileges. It cannot access the data membersdirectly and has to use dot operator as objectname.membername(here, dot is a direct membership access operator). The function is declared with keyword friend. But while defining friend function it does not use either keyword friend or :: operator. To illustrate the use of friend function #include <iostream.h> classmyclass int a,b; voidsetvalue(int i, int j); friendint add(myclassobj); ; voidmyclass::setvalue(int i,int j) a = i; b = j; int add(myclassobj) return (obj.a+obj.b); int main() myclass object; Sum of 34 and 56 is 90
4 object.setvalue(34, 56); cout<<"sum of 34 and 56 is "<<add(object)<<endl; return 0; To find the factorial of a number class factorial int n, fact; void read(); friendint facto(factorial x); ; void factorial::read() cout<<"enter the number: "; cin>>n; int facto(factorial x) x.fact = 1; for(int i=1; i<=x.n; i++) x.fact =x.fact * i; return(x.fact); factorial F; F.read(); cout<<"factorial = "<<facto(f); To find the total marks of four subjects of a student: Enter the number: 5 Factorial = 120 #include <iostream.h> class addition int m1, m2, m3, m4; voidsetvalue(into, intp, intq, int r); friendint total(addition s); ; void addition:: setvalue(into, intp, intq, int r) m1 = o; m2 = p; m3 = q; m4 = r; int total(addition s) return (s.m1 + s.m2+s.m3 + s.m4); int main() Total marks: 200 addition s1; s1.setvalue(50, 50, 50, 50); cout<< "Total marks: "<<total(s1)<<endl; return 0;
5 To find the total salary of husband and wife: #include <iostream.h> #include<iomanip.h> class wife; class husband char name[10]; int voidgetdata() salary; cout<<"enter the name of the husband: "; cin>>name; cout<<"enter the salary of the husband: "; cin>>salary; friendinttotalsal(husband h, wife w); ; class wife char name[10]; int salary; voidgetdata() cout<<"enter the name of the wife: "; cin>>name; cout<<"enter the salary of the wife: "; cin>>salary; friendinttotalsal(husband h, wife w); ; inttotalsal(husband h, wife w) cout<<"husband salary: "<<h.salary<<endl; cout<<"wife salary: "<<w.salary<<endl; return(h.salary + w.salary); husbandhs; wife wf; hs.getdata(); wf.getdata(); cout<< "Total salary: "<<totalsal(hs, wf); C++ program to swap the values of two variables using friend functions (using reference variables). #include<iomanip.h> class exchange int a, b; void read(); void print(); Enter the name of the husband: Rajappa Enter the salary of the husband: 5000 Enter the name of the wife: Shyla Enter the salary of the wife: 7500 Husband salary: 5000 Wife salary: 7500 Total salary: 12500
6 friend void swap(exchange &x); ; void exchange::read() cout<<"enter two numbers: "; cin>>a>>b; void exchange::print() cout<<"a="<<a<<" b= "<<b<<endl; void swap(exchange &x) int temp = x.a; x.a = x.b; x.b = temp; exchange E; E.read(); cout<<"before swapping: "; E.print(); swap(e); cout<<"after swapping: "; E.print(); C++ program to swap the values of two variables using friend functions (using pointers). #include<iomanip.h> class exchange int a, b; void read(); void print(); friend void swap(exchange *x); ; void exchange::read() cout<<"enter two numbers: "; cin>>a>>b; void exchange::print() cout<<"a="<<a<<" b= "<<b<<endl; void swap(exchange *x) int temp = x->a; x->a = x->b; x->b = temp; exchange E; E.read(); cout<<"before swapping: "; E.print(); swap(&e); Enter two numbers: Before swapping: a=10 b= 20 After swapping: a=20 b= 10 Enter two numbers: Before swapping: a=10 b= 20 After swapping: a=20 b= 10
7 cout<<"after swapping: "; E.print(); Function overloading: Function overloading is the capability of using the name of the function to perform different tasks. A function is said to be overloaded when it has one name, but more than one distinct meaning and applications. Function overloading therefore is the process of defining same function name to carry out similar types of activities with various data items. Advantages of function overloading or need for function overloading: Note: The code is executed faster. It is easier to understand the flow of information and debug. Code maintenance is easy. Easier interface between programs and real world objects. The main factor in function overloading is a functions argument list. C++ can distinguish overloaded functions by the number and type of arguments. If there are two functions having same name and different types of arguments or different number of arguments, then function overloading is invoked automatically by the compiler. Function overloading is also known as Compile time polymorphism. Example: int sum(int a, int b); float sum(float p, float q); The function sum() that takes two integer arguments is different from the function sum() that takes two float arguments. This is function overloading. To overload a function, each overloaded function must be declared and defined separately. Example: int product(int p, int q, int r); float product(float x,float y, float z); int product(int p, int q, int r) cout<<"product="<<p*q*r<<endl; float product(float x,float y,float z) cout<<"product="<<x*x*y*y*z*z<<endl; In this example the function product() is overloaded twice. The compiler automatically chooses the right type of function depending on the number of arguments. To compute volume of cone, cube cylinder and cuboid using function overloading. #include<conio.h> classfunoverload
8 int volume(ints) returns*s*s; //Volume of Cubes 3 double volume(double r, double h) // Volume of Cone return ((1/3)*3.143*r*r*h); // 1/3*πr 2 h π = 22 7 double volume(double r, int h) // Volume of Cylinder return (3.143*r*r*h); // πr 2 h double volume(double l, double b, double h) //Volume of Cuboid return (l*b*h); Volume of the Cube: 1000 ; Volume of the Cone: int main() Volume of the Cylinder: Volume of the Cuboid: 210 funoverload f1; cout<<"volume of the Cube: "<<f1.volume(10)<<endl; cout<<"volume of the Cone: "<<f1.volume(2.0,3.0)<<endl; cout<<"volume of the Cylinder: "<<f1.volume(2.0,3)endl; cout<<"volume of the Cuboid: "<<f1.volume(5.0,6.0,7.0)<<endl; return 0; To find the sum and concatenation by function overloading #include <iostream.h> #include<iomanip.h> #include<string.h> class overload int a, b; char s1[10], s2[10]; void fun() cout<<"enter two numbers: "; cin>>a>>b; cout<<"enter the first string: "; cin>>s1; cout<<"enter the second string: "; cin>>s2; add(s1, s2); cout<<"concatenated string: "<<s1<<endl; cout<<"sum: "<<add(a,b); void add(char *s1, char *s2); int add(int, int); ; void overload::add(char *s1, char *s2) strcat(s1, s2); intoverload::add(int, int) return(a+b); Enter two numbers: Enter the first string: Raj Enter the second string: appa Concatenated string: Rajappa sum: 30
9 overload f; f.fun(); To find the area of square, rectangle and triangle using function overloading #include<process.h> #include<iomanip.h> classfunoverload double area(double a) return a*a; double area(double l, double b) Enter the number of sides (1, 2 and 3): 1 return (l*b); Enter the side: 4.5 Area of the square = double area(double a, double b, double c) Enter the number of sides (1, 2 and 3): 2 floats=(a+b+c)/2.0; Enter two sides: return(sqrt(s*(s-a)*(s-b)*(s-c))); Area of the rectangle = ; clrscr(); double x, y, z; intans; funoverload f; Enter the number of sides (1, 2 and 3): 3 Enter three sides: Area of a triangle = Enter the number of sides (1, 2 and 3): 5 Invalid input cout<<"enter the number of sides(1, 2 and 3): "; cin>>ans; if (ans == 1) cout<<"enter the side: "; cin>>x; cout<<"area of the square = "<<f.area(x)<<endl; else if(ans == 2) cout<<"enter two sides: "; cin>>x>>y; cout<<"area of the rectangle= "<<f.area(x,y)<<endl; else if(ans == 3) cout<<"enter three sides: "; cin>>x>>y>>z; cout<<setprecision(8); cout<<"area of a triangle = " <<f.area(x,y,z)<<endl; else cout<<"invalid input"; getch();
10 One mark questions 1. What is meant by function overloading? 2. When is function overloading needed? 3. Write an advantage of function overloading. 4. Name one condition for overloading of functions. 5. What is an inline function? 6. Write one advantage of inline function. 7. The inline function is always converted to a code block. True/false 8. What is a friend function? 9. Write an example for friend function declaration. 10. Write one condition for using a friend function. 11. Can the key word friend be used while declaring a friend function? 12. Overloading a function means using different names to perform the same operations. True/false Two marks questions 1. What is meant by overloading implements polymorphism? 2. Write example for definition and declaration of function overloading 3. What are the restrictions on overloaded functions? 4. What are inline functions? Give an example. 5. Write the advantages of inline functions. 6. Create an inline function to check whetherthe number is Prime or not. 7. When are friend functions used? Write syntax for declaration of friend function. 8. Write any two characteristics of friend function. Three mark questions 1. Write any three reasons for function overloading. 2. What are the advantages of inline functions? 3. Write the advantages and disadvantages of inline functions. 4. When is it possible that an inline function may not work? 5. Write any three characteristics of friend function. Five mark questions 1. Explain the need for function overloading. 2. Discuss overloaded functions with syntax and example. 3. Explain inline functions with syntax and example. 4. Explain friend functions and their characteristics. *****
PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
Subtopics - Functions Function Declaration Function Arguments Return Statements and values. By Hardeep Singh
Subtopics - Functions Function Declaration Function Arguments Return Statements and values FUNCTIONS Functions are building blocks of the programs. They make the programs more modular and easy to read
OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES CONSTRUCTORS AND DESTRUCTORS
CONSTRUCTORS AND DESTRUCTORS Constructors: A constructor is a member function whose name is same as class name and is used to initialize data members and allocate memory dynamically. A constructor is automatically
Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is
Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
The C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
Calculating Area, Perimeter and Volume
Calculating Area, Perimeter and Volume You will be given a formula table to complete your math assessment; however, we strongly recommend that you memorize the following formulae which will be used regularly
www.sahajsolns.com Chapter 4 OOPS WITH C++ Sahaj Computer Solutions
Chapter 4 OOPS WITH C++ Sahaj Computer Solutions 1 Session Objectives Classes and Objects Class Declaration Class Members Data Constructors Destructors Member Functions Class Member Visibility Private,
Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553]
Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553] Books: Text Book: 1. Bjarne Stroustrup, The C++ Programming Language, Addison Wesley 2. Robert Lafore, Object-Oriented
Chapter 13 Storage classes
Chapter 13 Storage classes 1. Storage classes 2. Storage Class auto 3. Storage Class extern 4. Storage Class static 5. Storage Class register 6. Global and Local Variables 7. Nested Blocks with the Same
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
C++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms
PROG0101 FUNDAMENTALS OF PROGRAMMING Chapter 3 1 Introduction to A sequence of instructions. A procedure or formula for solving a problem. It was created mathematician, Mohammed ibn-musa al-khwarizmi.
Object Oriented Software Design II
Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February
Lecture 22: C Programming 4 Embedded Systems
Lecture 22: C Programming 4 Embedded Systems Today s Goals Basic C programming process Variables and constants in C Pointers to access addresses Using a High Level Language High-level languages More human
Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1
Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1 Introduction to Classes Classes as user-defined types We have seen that C++ provides a fairly large set of built-in types. e.g
The programming language C. sws1 1
The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
Revision Notes Adult Numeracy Level 2
Revision Notes Adult Numeracy Level 2 Place Value The use of place value from earlier levels applies but is extended to all sizes of numbers. The values of columns are: Millions Hundred thousands Ten thousands
Chapter 5 Functions. Introducing Functions
Chapter 5 Functions 1 Introducing Functions A function is a collection of statements that are grouped together to perform an operation Define a function Invoke a funciton return value type method name
More C++ Concepts. Operator overloading Friend Function This Operator Inline Function
More C++ Concepts Operator overloading Friend Function This Operator Inline Function 1 Review There are different types of member functions in the definition of a class Accessor int Str :: get_length();
Computer Science 1 CSci 1100 Lecture 3 Python Functions
Reading Computer Science 1 CSci 1100 Lecture 3 Python Functions Most of this is covered late Chapter 2 in Practical Programming and Chapter 3 of Think Python. Chapter 6 of Think Python goes into more detail,
Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)
Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
Introduction to Data Structures
Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate
Keil C51 Cross Compiler
Keil C51 Cross Compiler ANSI C Compiler Generates fast compact code for the 8051 and it s derivatives Advantages of C over Assembler Do not need to know the microcontroller instruction set Register allocation
C++FA 5.1 PRACTICE MID-TERM EXAM
C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer
(Eng. Hayam Reda Seireg) Sheet Java
(Eng. Hayam Reda Seireg) Sheet Java 1. Write a program to compute the area and circumference of a rectangle 3 inche wide by 5 inches long. What changes must be made to the program so it works for a rectangle
Comp151. Definitions & Declarations
Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;
C++ Outline Notes taken from: - Drake, Caleb. EECS 370 Course Notes, University of Illinois Chicago, Spring 97. Chapters 9, 10, 11, 13.1 & 13.2 - Horstman, Cay S. Mastering Object-Oriented Design in C++.
PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON
PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London
Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements
9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending
Introduction to Java. CS 3: Computer Programming in Java
Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods
Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }
Functions Recursion C++ functions Declare/prototype int myfunction (int ); Define int myfunction (int x){ int y = x*x; return y; Call int a; a = myfunction (7); function call flow types type of function
Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism
Polymorphism Problems with switch statement Programmer may forget to test all possible cases in a switch. Tracking this down can be time consuming and error prone Solution - use virtual functions (polymorphism)
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Chapter One Introduction to Programming
Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of
Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)
Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking
PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE
PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :
Java Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
Java Basics: Data Types, Variables, and Loops
Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables
COMPUTER SCIENCE 1999 (Delhi Board)
COMPUTER SCIENCE 1999 (Delhi Board) Time allowed: 3 hours Max. Marks: 70 Instructions: (i) All the questions are compulsory. (ii) Programming Language: C++ QUESTION l. (a) Why main function is special?
Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C
Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in
Java CPD (I) Frans Coenen Department of Computer Science
Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials
Habanero Extreme Scale Software Research Project
Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead
Pseudo code Tutorial and Exercises Teacher s Version
Pseudo code Tutorial and Exercises Teacher s Version Pseudo-code is an informal way to express the design of a computer program or an algorithm in 1.45. The aim is to get the idea quickly and also easy
Example of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
Introduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
Variables, Constants, and Data Types
Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight
Chapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named
Subject Name: Object Oriented Programming in C++ Subject Code: 2140705
Faculties: L.J. Institute of Engineering & Technology Semester: IV (2016) Subject Name: Object Oriented Programming in C++ Subject Code: 21405 Sr No UNIT - 1 : CONCEPTS OF OOCP Topics -Introduction OOCP,
Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c
Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection
SURFACE AREAS AND VOLUMES
CHAPTER 1 SURFACE AREAS AND VOLUMES (A) Main Concepts and Results Cuboid whose length l, breadth b and height h (a) Volume of cuboid lbh (b) Total surface area of cuboid 2 ( lb + bh + hl ) (c) Lateral
C++ Language Tutorial
cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain
Basic Object-Oriented Programming in Java
core programming Basic Object-Oriented Programming in Java 1 2001-2003 Marty Hall, Larry Brown http:// Agenda Similarities and differences between Java and C++ Object-oriented nomenclature and conventions
C++FA 3.1 OPTIMIZING C++
C++FA 3.1 OPTIMIZING C++ Ben Van Vliet Measuring Performance Performance can be measured and judged in different ways execution time, memory usage, error count, ease of use and trade offs usually have
Chapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
Programming Language Features (cont.) CMSC 330: Organization of Programming Languages. Parameter Passing in OCaml. Call-by-Value
CMSC 33: Organization of Programming Languages Programming Language Features (cont.) Names & binding Namespaces Static (lexical) scopes Dynamic scopes Polymorphism Parametric Subtype Ad-hoc Parameter Passing
Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75
Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]
Course notes Standard C++ programming
Department of Cybernetics The University of Reading SE2B2 Further Computer Systems Course notes Standard C++ programming by Dr Virginie F. Ruiz November, 03 CREATING AND USING A COPY CONSTRUCTOR... 27
I PUC - Computer Science. Practical s Syllabus. Contents
I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui
Compiler Construction
Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from
Curriculum Map. Discipline: Computer Science Course: C++
Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code
Data Structures using OOP C++ Lecture 1
References: 1. E Balagurusamy, Object Oriented Programming with C++, 4 th edition, McGraw-Hill 2008. 2. Robert Lafore, Object-Oriented Programming in C++, 4 th edition, 2002, SAMS publishing. 3. Robert
An Incomplete C++ Primer. University of Wyoming MA 5310
An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages
While Loop. 6. Iteration
While Loop 1 Loop - a control structure that causes a set of statements to be executed repeatedly, (reiterated). While statement - most versatile type of loop in C++ false while boolean expression true
10CS35: Data Structures Using C
CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a
CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
Application Note C++ Debugging
Application Note C++ Debugging TRACE32 Online Help TRACE32 Directory TRACE32 Index TRACE32 Documents... High-Level Language Debugging... Application Note C++ Debugging... 1 Sample Code used by This Application
MXwendler Javascript Interface Description Version 2.3
MXwendler Javascript Interface Description Version 2.3 This document describes the MXWendler (MXW) Javascript Command Interface. You will learn how to control MXwendler through the Javascript interface.
C++ Overloading, Constructors, Assignment operator
C++ Overloading, Constructors, Assignment operator 1 Overloading Before looking at the initialization of objects in C++ with constructors, we need to understand what function overloading is In C, two functions
KITES TECHNOLOGY COURSE MODULE (C, C++, DS)
KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php [email protected] [email protected] Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL
CS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
C PROGRAMMING FOR MATHEMATICAL COMPUTING
UNIVERSITY OF CALICUT SCHOOL OF DISTANCE EDUCATION BSc MATHEMATICS (2011 Admission Onwards) VI Semester Elective Course C PROGRAMMING FOR MATHEMATICAL COMPUTING QUESTION BANK Multiple Choice Questions
Lecture 5: Java Fundamentals III
Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd
Object Oriented Software Design II
Object Oriented Software Design II C++ intro Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 26, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 26,
Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example
Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include
Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!
Programming Language Rankings Lecture 15: Type Inference, polymorphism & Type Classes CSC 131 Fall, 2014 Kim Bruce Top Combined Tiobe Index 1. JavaScript (+1) 2. Java (-1) 3. PHP 4. C# (+2) 5. Python (-1)
Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT
BSc (Hons) in Computer Applications, BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems & BSc (Hons) Software Engineering Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT
Java Crash Course Part I
Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe [email protected] Overview (Short) introduction to the environment Linux
Geometry - Calculating Area and Perimeter
Geometry - Calculating Area and Perimeter In order to complete any of mechanical trades assessments, you will need to memorize certain formulas. These are listed below: (The formulas for circle geometry
7 Literal Equations and
CHAPTER 7 Literal Equations and Inequalities Chapter Outline 7.1 LITERAL EQUATIONS 7.2 INEQUALITIES 7.3 INEQUALITIES USING MULTIPLICATION AND DIVISION 7.4 MULTI-STEP INEQUALITIES 113 7.1. Literal Equations
Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard
INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard
Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class
CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class This homework is to be done individually. You may, of course, ask your fellow classmates for help if you have trouble editing files,
Syllabus OBJECT ORIENTED PROGRAMMING C++
1 Syllabus OBJECT ORIENTED PROGRAMMING C++ 1. Introduction : What is object oriented programming? Why do we need objectoriented. Programming characteristics of object-oriented languages. C and C++. 2.
VB.NET Programming Fundamentals
Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements
PRI-(BASIC2) Preliminary Reference Information Mod date 3. Jun. 2015
PRI-(BASIC2) Table of content Introduction...2 New Comment...2 Long variable...2 Function definition...3 Function declaration...3 Function return value...3 Keyword return inside functions...4 Function
Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:
In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our
Syllabus for Computer Science. Proposed scheme for B.Sc Programme under Choice Based Credit System
Syllabus for Computer Science Proposed scheme for B.Sc Programme under Choice Based Credit System SEMESTER - I Code Course Title Course Type HPW Credits BS106 SEMESTER -I I BS 206 SEMESTER -III BS 301
Semester Review. CSC 301, Fall 2015
Semester Review CSC 301, Fall 2015 Programming Language Classes There are many different programming language classes, but four classes or paradigms stand out:! Imperative Languages! assignment and iteration!
Calling the Function. Two Function Declarations Here is a function declared as pass by value. Why use Pass By Reference?
Functions in C++ Let s take a look at an example declaration: Lecture 2 long factorial(int n) Functions The declaration above has the following meaning: The return type is long That means the function
El Dorado Union High School District Educational Services
El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.
The Clean programming language. Group 25, Jingui Li, Daren Tuzi
The Clean programming language Group 25, Jingui Li, Daren Tuzi The Clean programming language Overview The Clean programming language first appeared in 1987 and is still being further developed. It was
University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python
Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.
