3-UML_intro_class_S09

3-UML_intro_class_S09 - Introduction to Classes and Objects...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Classes and Objects
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C++ Functions To implement large projects, the problem is divided into smaller parts (tasks) and a solution for each of these tasks. Theses partial solutions to the big problem are called sub-programs (modules). In C++ these modules are called functions. Functions are sub-programs designed to perform a task in C++. They are called when necessary to perform the task.
Background image of page 2
Value-Returning Functions Syntax: Return_type Function_name( Formal Parameters) { C++ code to perform the task and find the result return result; } Return_type : Data type of the value returned by the function Also called the function type Function_name: Identifier used to name the function and is used to call the function. Formal Parameters: List of variables representing input/output to and from the function. Are used to communicated with the caller.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Value returning Function: Example float Calc_salary( float hrs, float Pay_Rate) // Return_type Function_name( Formal Parameters: hrs and Pay_Rate) { float Salary ; // Local Variables Salary = hrs * Pay_Rate ; //Calculation return Salary ; // Sending back the result } // Function call float Hours, Pay_Rate, Salary ; cin >> Hours >> Pay_Rate ; Salary = Calc_salary (Hours, Pay_Rate); cout << “Your salary is: “ << Salary << endl ;
Background image of page 4
Void functions These functions do not return a value, they perform a task and will return control to calling function. Sample void Print_Report (float Average, char Grade) { cout <<“\nYour average is: “ << Average ; cout <<“\nYour letter grade is: “ << Grade ; } Calling a void function Print_Report(Avg, Letter_Garde);
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Program Example #include <iostream> using namespace std; int main(){ float Width= 5, Length=7, Area, Perimeter; Area = Width * Length ; Perimeter = (Width + Length) * 2 ; cout << "Area of Rectangle: " << Area << endl ; cout << “Perimeter of Rectangle: " << Perimeter << endl ;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/03/2009 for the course CSCI 101L taught by Professor Ghyam during the Spring '07 term at USC.

Page1 / 23

3-UML_intro_class_S09 - Introduction to Classes and Objects...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online