C++ Object-Oriented Programming Concepts PDF
Document Details
Uploaded by VersatileParabola
Swami Ramanand Teerth Marathwada University
Tags
Summary
This document provides an introduction to fundamental Object-Oriented Programming (OOP) concepts using the C++ programming language. It details topics such as classes, objects, encapsulation, data abstraction, inheritance, and polymorphism. These concepts are crucial for developing well-structured, maintainable, and reusable C++ programs.
Full Transcript
# Unit-I ## Introduction **Object Oriented Programming** Object-oriented programming is defined as an approach that provides a way of modularising programs by creating partitioned memory areas for both data and functions which can be used as templates for creating copies of such modules on demand...
# Unit-I ## Introduction **Object Oriented Programming** Object-oriented programming is defined as an approach that provides a way of modularising programs by creating partitioned memory areas for both data and functions which can be used as templates for creating copies of such modules on demand. Writing object-oriented programs involves creating classes, creating objects from those classes, and creating applications, which are standalone executable programs that use those objects. Once created, classes can be reused over and over again to develop new programs. Thinking in an object-oriented manner involves envisioning program components as objects which belong to classes and are similar to concrete objects in the real world. You can manipulate these objects and have them interrelate with each other to achieve a desired result. ## Basic Concepts of Object-Oriented Programming ### 1. Class A class is a user-defined data type. It is a logical abstraction. A class is a template that defines the form of an object. It specifies both code and data. A physical representation of a class does not exist in memory until an object of that class has been created. When defining a class, you declare the data it contains and the code that operates on that data. Data is contained in instance variables defined by the class known as data members, and code is contained in functions known as member functions. The code and data that constitute a class are called members of the class. ### 2. Object An object is an identifiable entity with specific characteristics and behavior. It is said to be an instance of a class. Defining an object is similar to defining a variable of any data type: Space is set aside for it in memory. ### 3. Encapsulation Encapsulation is a programming mechanism that binds together code and the data it manipulates and keeps both safe from outside interference and misuse. In C++, the basic unit of encapsulation is the class. Within a class, code or data, or both, may be private to that object or public. Private code or data is known to and accessible by only another part of the object. In other words, private code or data cannot be accessed by a piece of the program that exists outside the object. When code or data is public, other parts of your program can access it even though it is defined within an object. Typically, the public parts of an object are used to provide a controlled interface to the private elements of the object. This insulation of the data from direct access by the program is called data hiding. ### 4. Data abstraction In object-oriented programming, each object will have external interfaces through which it can be made use of. There is no need to look into its inner details. An object may be made of many smaller objects with proper interfaces. The user only needs to know the external interfaces to make use of an object. The internal details of objects are hidden which makes them abstract. This technique of hiding internal details in a object is called data abstraction. ### 5. Inheritance Inheritance is the mechanism by which one class can inherit the properties of another. It allows a hierarchy of classes to be built, moving from the most general to the most specific. When one class is inherited by another, the class that is inherited is called the base class. The inheriting class is called the derived class. The process of inheritance begins with the definition of a base class. The base class defines all qualities common to any derived class. In OOPs, the concept of inheritance provides the idea of reusability. The base class represents the most general description of a set of traits. The derived class inherits those general traits and adds properties that are specific to that class. ### 6. Polymorphism Polymorphism (from the Greek, meaning "many forms") is a feature that allows one interface to be used for a general class of actions. The specific action is determined by the exact nature of the situation. This concept of polymorphism is often expressed by the phrase “one interface, multiple methods”. This means that it is possible to design a generic interface to a group of related activities. This helps reduce complexity by allowing the same interface to be used to specify a general class of action. The compiler's job is to select the specific action as it applies to each situation. # Unit-II ## Control Structures Control structures allow you to control the flow of a program's execution based on certain conditions. C++ supports the following basic control structures: 1. Selection Control Structure 2. Loop Control Structure ### 1) Selection Control Structures Selection Control Structures allow you to control the flow of a program's execution depending upon the state of a particular condition being true or false. C++ supports two types of selection statements: *if* and *switch*. The *?:* conditional operator can also be used as an alternative to the *if* statement. #### A.1) If Statement The syntax of an if statement in C++ is: ```c++ if(condition) { // statement(s) will execute if the condition is true } ``` If the condition evaluates to true, then the block of code inside the if statement will be executed. If it evaluates to false, then the first set of code after the end of the if statement (after the closing curly brace) will be executed. #### A.2) The if…else Statement The syntax is shown as: ```c++ if(condition) { // statement(s) will execute if the condition is true } else { // statement(s) will execute if condition is false } ``` If the condition evaluates to true, then the if block of code will be executed, otherwise else block of code will be executed. #### A.3) if…else if…else Statement An if statement can be followed by an optional else if…else statement, which is very useful to test various conditions using a single if…else if statement. The syntax is shown as: ```c++ if(condition 1){ // Executes when the condition 1 is true } else if(condition 2){ // Executes when the condition 2 is true } else if(condition 3){ // Executes when the condition 3 is true } else { // executes when the none of the above condition is true. } ``` #### A.4) Nested if Statement It is always legal to nest if-else statements, which means you can use one if or else if statement inside another if or else if statement(s). The syntax for a nested if statement is as follows: ```c++ if(condition 1){ // Executes when the condition 1 is true if(condition 2){ // Executes when the condition 2 is true } } ``` #### B) Switch C++ has a built-in multiple-branch selection statement, called switch, which successively tests the value of an expression against a list of integer or character constants. When a match is found, the statements associated with that constant are executed. The general form of the switch statement is: ```c++ switch (expression) { case constant1: statement sequence break; case constant2: statement sequence break; case constant3: statement sequence break; default: statement sequence } ``` The expression must evaluate to a character or integer value. Floating-point expressions, for example, are not allowed. The value of expression is tested, in order, against the values of the constants specified in the case statements. When a match is found, the statement sequence associated with that case is executed until the break statement or the end of the switch statement is reached. The *default* statement is executed if no matches are found. The default is optional and, if not present, no action takes place if all matches fail. The *break* statement is one of C++'s jump statements. You can use it in loops as well as in the switch statement. When *break* is encountered in a switch, program execution “jumps” to the line of code following the switch statement. ### 2) Loop Control Structures A loop statement allows us to execute a statement or group of statements multiple times. Loops or iterative statements tell the program to repeat a fragment of code several times or as long as a certain condition holds. C++ provides three convenient iterative statements: *while*, *for*, and *do-while*. #### while Loop A while loop statement repeatedly executes a target statement as long as a given condition is true. It is an entry-controlled loop. The syntax of a while loop in C++ is: ```c++ while(condition){ statement(s); } ``` Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any non-zero value. The loop iterates while the condition is true. After each execution of the loop, the value of test expression is changed. When the condition becomes false, program control passes to the line immediately following the loop. #### The do-while Loop The do-while loop differs from the while loop in that the condition is tested after the body of the loop. This assures that the program goes through the iteration at least once. It is an exit-controlled loop. ```c++ do { statement(s); } while( condition ); ``` The conditional expression appears at the end of the loop, so the statement(s) in the loop execute once before the condition is tested. If the condition is true, the flow of control jumps back up to *do*, and the statement(s) in the loop execute again. This process repeats until the given condition becomes false. #### for Loop A *for* loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. The syntax of a *for* loop in C++ is: ```c++ for (init; condition; increment){ statement(s); } ``` Here is the flow of control in a *for* loop: 1. The *init* step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears. 2. Next, the *condition* is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and flow of control jumps to the next statement just after the *for* loop. 3. After the body of the *for* loop executes, the flow of control jumps back up to the *increment* statement. This statement allows you to update any C++ loop control variables. This statement can be left blank, as long as a semicolon appears after the condition. 4. The *condition* is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then increment step, and then again condition). After the condition becomes false, the *for* loop terminates. # Unit-III ## Class A class is a user-defined data type. It is a logical abstraction. A class is a template that defines the form of an object. It specifies both code and data. A physical representation of a class does not exist in memory until an object of that class has been created. When defining a class, you declare the data it contains and the code that operates on that data. Data is contained in instance variables defined by the class known as data members, and code is contained in functions known as member functions. The code and data that constitute a class are called members of the class. The general form of a class declaration is: ```c++ class class-name { access-specifier: data and functions access-specifier: data and functions // ... access-specifier: data and functions } object-list; ``` The *object-list* is optional. If present, it declares objects of the class. Here, access-specifier is one of these three C++ keywords: * *public* * *private* * *protected* By default, functions and data declared within a class are *private* to that class and may be accessed only by other members of the class. The *public* access specifier allows functions or data to be accessible to other parts of your program. The *protected* access specifier is needed only when inheritance is involved. ## Object An object is an identifiable entity with specific characteristics and behavior. It is said to be an instance of a class. Defining an object is similar to defining a variable of any data type: Space is set aside for it in memory. ## Accessing Class Members The main() function cannot contain statements that access class members directly. Class members can be accessed only by an object of that class. To access class members, use the dot (.) operator. The dot operator links the name of an object with the name of a member. The general form of the dot operator is shown here: ```c++ object.member ``` The private members of a class cannot be accessed directly using the dot operator, but through the member functions of that class providing data hiding. A member function can call another member function directly, without using the dot operator. ## Constructor A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever an object of its associated class is created. It is called constructor because it constructs the value data members of the class. The constructor functions have some special characteristics: * They should be declared in the *public* section. * They are invoked automatically when the objects are created. * They do not have return types, not even *void* and therefore, they cannot return values. * They cannot be inherited, though a derived class can call the base class constructor. ## Default constructor The default constructor for any class is the constructor with no arguments. When no arguments are passed, the constructor will assign the values specifically assigned in the body of the constructor. It can be zero or any other value. The default constructor can be identified by the name of the class followed by empty parentheses. If it is not defined explicitly, then it is automatically defined implicitly by the system. ## Parameterized Constructor It is possible to pass arguments to constructors. Typically, these arguments help initialize an object when it is created. To create a parameterized constructor, simply add parameters to it the way you would to any other function. When you define the constructor's body, use the parameters to initialize the object. ## Copy Constructors The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. If class definition does not explicitly include copy constructor, then the system automatically creates one by default. The copy constructor is used to: * Initialize one object from another of the same type. * Copy an object to pass it as an argument to a function. * Copy an object to return it from a function. ## Destructor A destructor destroys an object after it is no longer in use. The destructor, like constructor, is a member function with the same name as the class name. But it will be preceded by the character tilde (~). A destructor takes no arguments and has no return value. Each class has exactly one destructor. If class definition does not explicitly include destructor, then the system automatically creates one by default. It will be invoked implicitly by the compiler upon exit from the program to clean up storage that is no longer accessible. ## Friend function In general, only other members of a class have access to the private members of the class. However, it is possible to allow a nonmember function access to the private members of a class by declaring it as a friend of the class. To make a function a friend of a class, you include its prototype in the class declaration and precede it with the *friend* keyword. The function is declared with *friend* keyword. But while defining friend function, it does not use either keyword *friend* or *::* operator. A function can be a friend of more than one class. Member function of one class can be friend functions of another class. In such cases they are defined using the scope resolution operator. ## Operator Overloading There is another useful methodology in C++ called operator overloading. The language allows not only functions to be overloaded, but also most of the operators, such as +, -, *, /, etc. As the name suggests, here the conventional operators can be programmed to carry out more complex operations. This overloading concept is fundamentally the same i.e. the same operators can be made to perform different operations depending on the context. Such operators have to be specifically defined and appropriate function programmed. When an operator is overloaded, none of its original meaning is lost. It is simply that a new operation, relative to a specific class, is defined. For example, a class that defines a linked list might use the + operator to add an object to the list. A class that implements a stack might use the + to push an object onto the stack. An operator function defines the operations that the overloaded operator will perform relative to the class upon which it will work. An operator function is created using the keyword operator. The general form of an operator function is: ```c++ type classname::operator#(arg-list) { // operations } ``` Here, the operator that you are overloading is substituted for the #, and *type* is the type of value returned by the specified operation. Operator functions can be either members or nonmembers of a class. Nonmember operator functions are often friend functions of the class. These operators cannot be overloaded: *.** :** , *::*, *.*, *,* The process of operator overloading involves the following steps: * Create a class that defines the data type that is to be used in the overloading operation. * Declare the operator function *operator op()* in the public part of the class. * Define the operator function to implement the required operations. ## This Pointer It is facilitated by another interesting concept of C++ called *this* pointer. *this* is a C++ keyword. *this* always refers to an object that has called the member function currently. We can say that *this* is a pointer. It points to the object that has called this function this time. While overloading binary operators, we use two objects, one that called the operator function and the other, which is passed to the function. We referred to the data member of the calling object, without any prefix. However, the data member of the other object had a prefix. Always *this* refers to the calling object place of the object name. ## Inheritance Inheritance is the mechanism by which one class can inherit the properties of another. It allows a hierarchy of classes to be built, moving from the most general to the most specific. When one class is inherited by another, the class that is inherited is called the base class. The inheriting class is called the derived class. The process of inheritance begins with the definition of a base class. The base class defines all qualities that will be common to any derived class. In essence, the base class represents the most general description of a set of traits. The derived class inherits those general traits and adds properties that are specific to that class. When one class inherits another, it uses this general form: ```c++ class derived-class-name: access base-class-name { // ... } ``` Here *access* is one of the three keywords: *public*, *private*, or *protected*. The access specifier determines how elements of the base class are inherited by the derived class. ## Virtual Function A virtual function is a member function that is declared within a base class and redefined by a derived class. In order to make a function virtual, you have to add keyword virtual in front of a function definition. When a class containing a virtual function is inherited, the derived class redefines the virtual function relative to the derived class. The virtual function within the base class defines the form of the interface to that function. Each redefinition of the virtual function by a derived class implements its operation as it relates specifically to the derived class. That is, the redefinition creates a specific method. When a virtual function is redefined by a derived class, the keyword virtual is not needed. A virtual function can be called just like any member function. However, what makes a virtual function interesting, and capable of supporting run-time polymorphism, is what happens when a virtual function is called through a pointer. When a base pointer points to a derived object that contains a virtual function and that virtual function is called through that pointer, C++ determines which version of that function will be executed based upon the type of object being pointed to by the pointer. And this determination is made at run time. Therefore, if two or more different classes are derived from a base class that contains a virtual function, then when different objects are pointed to by a base pointer, different versions of the virtual function are executed. ## Pure virtual functions Sometimes when a virtual function is declared in the base class, there is no meaningful operation for it to perform. This situation is common because often a base class does not define a complete class by itself. Instead, it simply supplies a core set of member functions and variables to which the derived class supplies the remainder. When there is no meaningful action for a base class virtual function to perform, the implication is that any derived class must override this function. To ensure that this will occur, C++ supports *pure virtual functions*. A pure virtual function has no definition relative to the base class. Only the function prototype is included. To make a pure virtual function, use this general form: ```c++ virtual type func-name(parameter-list) = 0; ``` The key part of this declaration is the setting of the function equal to 0. This tells the compiler that no body exists for this function relative to the base class. When a virtual function is made pure, it forces any derived class to override it. If a derived class does not, a compile-time error results. Thus, making a virtual function pure is a way to guaranty that a derived class will provide its own redefinition. ## Abstract class When a class contains atleast one pure virtual function, it is referred to as an abstract class. Since, an abstract class contains atleast one function for which no body exists, it is, technically, an incomplete type, and no objects of that class can be created. Thus, abstract classes exist only to be inherited. It is important to understand, however, that you can still create a pointer to an abstract class, since it is through the use of base class pointers that run-time polymorphism is achieved. (It is also possible to have a reference to an abstract class.). # Unit-IV ## Pointer A pointer is a variable that contains a memory address. Very often this address is the location of another object, such as a variable. For example, if x contains the address of y, then x is said to “point to” y. Pointer variables must be declared as such. The general form of a pointer variable declaration is: ```c++ type *var-name; ``` Here, *type* is the pointer's base type. The base type determines what type of data the pointer will be pointing to. *var-name* is the name of the pointer variable. ## Object Pointers We have been accessing members of an object by using the dot operator. However, it is also possible to access a member of an object via a pointer to that object. When a pointer is used, the arrow operator (->) rather than the dot operator is employed. We can declare an object pointer just as a pointer to any other type of variable is declared. Specify its class name, and then precede the variable name with an asterisk. To obtain the address of an object, precede the object with the & operator, just as you do when taking the address of any other type of variable. ## Pointers to Derived Types Pointers to base classes and derived classes are related in ways that other types of pointers are not. In general, a pointer of one type cannot point to an object of another type. However, base class pointers and derived objects are the exceptions to this rule. In C++, a base class pointer can also be used to point to an object of any class derived from that base. For example, assume that you have a base class called B and a class called D, which is derived from B. Any pointer declared as a pointer to B can also be used to point to an object of type D. Therefore, given: ```c++ B *p; //pointer p to object of type B B B_ob; //object of type B D D_ob; //object of type D ``` both of the following statements are perfectly valid: ```c++ p = &B_ob; //p points to object B p = &D_ob; //p points to object D, which is an object derived from B ``` A base pointer can be used to access only those parts of a derived object that were inherited from the base class. Thus, in this example, p can be used to access all elements of *D_ob* inherited from *B_ob*. However, elements specific to *D_ob* cannot be accessed through *p*. ## Virtual Function A virtual function is a member function that is declared within a base class and redefined by a derived class. In order to make a function virtual, you have to add keyword *virtual* in front of a function definition. When a class containing a virtual function is inherited, the derived class redefines the virtual function relative to the derived class. The virtual function within the base class defines the form of the interface to that function. Each redefinition of the virtual function by a derived class implements its operation as it relates specifically to the derived class. That is, the redefinition creates a specific method. When a virtual function is redefined by a derived class, the keyword *virtual* is not needed. A virtual function can be called just like any member function. However, what makes a virtual function interesting, and capable of supporting run-time polymorphism, is what happens when a virtual function is called through a pointer. When a base pointer points to a derived object that contains a virtual function and that virtual function is called through that pointer, C++ determines which version of that function will be executed based upon the type of object being pointed to by the pointer. And this determination is made at run time. Therefore, if two or more different classes are derived from a base class that contains a virtual function, then when different objects are pointed to by a base pointer, different versions of the virtual function are executed. ## Pure virtual functions Sometimes when a virtual function is declared in the base class, there is no meaningful operation for it to perform. This situation is common because often a base class does not define a complete class by itself. Instead, it simply supplies a core set of member functions and variables to which the derived class supplies the remainder. When there is no meaningful action for a base class virtual function to perform, the implication is that any derived class must override this function. To ensure that this will occur, C++ supports *pure virtual functions.* A pure virtual function has no definition relative to the base class. Only the function prototype is included. To make a pure virtual function, use this general form: ```c++ virtual type func-name(parameter-list) = 0; ``` The key part of this declaration is the setting of the function equal to 0. This tells the compiler that no body exists for this function relative to the base class. When a virtual function is made pure, it forces any derived class to override it. If a derived class does not, a compile-time error results. Thus, making a virtual function pure is a way to guaranty that a derived class will provide its own redefinition. ## Abstract class When a class contains atleast one pure virtual function, it is referred to as an abstract class. Since, an abstract class contains atleast one function for which no body exists, it is, technically, an incomplete type, and no objects of that class can be created. Thus, abstract classes exist only to be inherited. It is important to understand, however, that you can still create a pointer to an abstract class, since it is through the use of base class pointers that run-time polymorphism is achieved. (It is also possible to have a reference to an abstract class.). # Unit-V ## C++ Stream The C++ I/O system operates through streams. A stream is a logical device that either produces or consumes information. A stream is linked to a physical device by the C++ I/O system. All streams behave in the same manner, even if the actual physical devices they are linked to differ. Because all streams act the same, the I/O system presents the programmer with a consistent interface. Two types of streams: * *Output stream:* A stream that takes data from the program and sends (writes) it to destination. * *Input stream:* A stream that extracts (reads) data from the source and sends it to the program. C++ provides both the formatted and unformatted IO functions. In formatted or high-level IO, bytes are grouped and converted to types such as *int*, *double*, *string* or user-defined types. In unformatted or low-level IO, bytes are treated as raw bytes and unconverted. Formatted IO operations are supported via overloading the stream insertion (<<) and stream extraction (>>) operators, which presents a consistent public IO interface. C++ provides supports for its I/O system in the header file<iostream>. Just as there are different kinds of I/O (for example, input, output, and file access), there are different classes depending on the type of I/O. The following are the most important stream classes: * *Class istream* :- Defines input streams that can be used to carry out formatted and unformatted input operations. It contains the overloaded extraction (>>) operator functions. Declares input functions such *get()*, *getline()* and *read()*. * *Class ostream* :- Defines output streams that can be used to write data. Declares output functions *put* and *write()*. The *ostream* class contains the overloaded insertion (<<) operator function. When a C++ program begins, these four streams are automatically opened: | Stream | Meaning | Default Device | | :------- | :---------------- | :--------------- | | *cin* | Standard input | Keyboard | | *cout* | Standard output | Screen | | *cerr* | Standard error | Screen | | *clog* | Buffer version of cerr | Screen | ## Cin and Cout objects *cout* is an object of class ostream. The *cout* is a predefined object that represents the standard output stream in C++. Here, the standard output stream represents monitor. In the language of C++, the << operator is referred to as the insertion operator because it inserts data into a stream. It inserts or sends the contents of variable on its right to the object on its left. For example: ```c++ cout << "Programming in C++"; ``` Here << operator is called the stream insertion operator and is used to push data into a stream (in this case the standard output stream). *cin* is an object of class istream. *cin* is a predefined object that corresponds to the standard input stream. The standard input stream represents keyboard. The >> operator is called the extraction operator because it extracts data from a stream. It extracts or takes the value from the keyboard and assigns it to the variable on it's right. For example: ```c++ int number; cin >> number; ``` Here >> operator accepts value from keyboard and stores in variable number. ## Unformatted Input/Output Functions ### Functions get and put The *get()* function receives one character at a time. There are two prototypes available in C++ for *get* as given below: 1. *get(char *)* 2. *get()* Their usage will be clear from the example below: ```c++ char ch; cin.get (ch); ``` In the above, a single character typed on the keyboard will be received and stored in the character variable *ch*. Let us now implement the *get* function using the other prototype: ```c++ char ch; ch = cin.get(); ``` This is the difference in usage of the two prototypes of *get* functions. The complement of *get* function for output is the *put* function of the *ostream* class. It also has two forms as given below: 1. *cout.put(var);* 2. *cout.put ('a');* Here the value of the variable var will be displayed in the console monitor. We can also display a specific character directly as given below: ## getline and write functions C++ supports functions to read and write a line at one go. The *getline()* function will read one line at a time. The end of the line is recognized by a new line character, which is generated by pressing the Enter key. We can also specify the size of the line. The prototype of the *getline* function is given below: ```c++ cin.getline (var, size); ``` When we invoke the above statement, the system will read a line of characters contained in variable *var* one at a time. The reading will stop when it encounters a new line character or when the required number (size-1) of characters have been read, whichever occurs earlier. The new line character will be received when we enter a line of size less than specified and press the Enter key. The Enter key or Return key generates a new line character. This character will be read by the function but converted into a NULL character and appended to the line of characters. Similarly, the *write* function displays a line of given size. The prototype of the *write* function is given below: ```c++ write (var, size); ``` where *var* is the name of the string and *size* is an integer. ## Formatted I/O via manipulators The C++ I/O system allows you to format I/O operations. For example, you can set a field width, specify a number base, or determine how many digits after the decimal point will be displayed. I/O manipulators are special I/O format functions that can occur within an I/O statement. | Manipulator | Purpose | Input/Output | | :------------- | :------------------------------------------------------------------ | :------------ | | *boolalpha* | Turns on *boolaphaflag* | Input/Output | | *dec* | Turns on *decflag* | Input/Output | | *endl* | Outputs a newline character and flushes the stream | Output | | *ends* | Outputs a null | Output | | *fixed* | Turns on *fixed* flag | Output | | *flush* | Flushes a stream | Output | | *hex* | Turns on *hexflag* | Input/Output | | *internal* | Turns on *internalflag* | Output | | *left* | Turns on *leftflag* | Output | | *noboolalpha* | Turns off *boolalphaflag* | Input/Output | | *noshowbase* | Turns off *showbaseflag* | Output | | *noshowpoint* | Turns off *showpointflag* | Output | | *noshowpos* | Turns off *showposflag* | Output | | *noskipws* | Turns off *skipwsflag* | Input | | *nounitbuf* | Turns off *unitbufflag* | Output | | *nouppercase* | Turns off *uppercaseflag* | Output | | *oct* | Turns on *octflag* | Input/Output | | *resetiosflags(fmtflads f)* | Turns off the flags specified in f | Input/Output | | *right* | Turns on *rightflag* | Output | | *scientific* | Turns on *scientificflag* | Output | | *setbase(int base)* | Sets the number base to base | Input/Output | | *setfill(int ch)* | Sets the fill char ch | Output | | *setiosflags(fmtflags f)* | Turns on the flags specified by f | Input/Output | | *setprecision(int p)* | Sets the number of digits of precision | Output | | *setw(int w)* | Sets the field width to w | Output | | *showbase* | Turns on *showbaseflag* | Output | | *showpoint* | Turns on *showpointflag* | Output | | *showpos* | Turns on *showposflag* | Output | | *skipws* | Turns on *skipwsflag* | Input | | *unit