Sunday, 3 July 2016

Data Storage

We begin our study of computer science by considering how information is encoded and stored inside computers. Our first step is to discuss the basics of a computer’s data storage devices and then to consider how information is encoded for storage in these systems. We will explore the ramifications of today’s data storage systems and how such techniques as data compression and error handling are used to overcome their shortfalls.
Bits And Their Storage:
Inside today’s computers information is encoded as patterns of 0s and 1s. These digits are called bits (short for binary digits). Although you may be inclined to associate bits with numeric values, they are really only symbols whose meaning depends on the application at hand. Sometimes patterns of bits are used to represent numeric values; sometimes they represent characters in an alphabet and punctuation marks; sometimes they represent images; and sometimes they represent sounds.
Boolean Operation:
To understand how individual bits are stored and manipulated inside a computer, it is convenient to imagine that the bit 0 represents the value false and the bit 1 represents the value true because that allows us to think of manipulating bits as manipulating true/false values. Operations that manipulate
true/false values are called Boolean operations, in honor of the mathematician George Boole (1815–1864), who was a pioneer in the field of mathematics called logic. Three of the basic Boolean operations are AND, OR, and XOR (exclusive or) as summarized in Figure 1.1. These operations are similar to the arithmetic operations TIMES and PLUS because they combine a pair of values
(the operation’s input) to produce a third value (the output). In contrast to arithmetic operations, however, Boolean operations combine true/false values rather than numeric values.
The Boolean operation AND is designed to reflect the truth or falseness of a statement formed by combining two smaller, or simpler, statements with the conjunction and. Such statements have the generic form
P AND Q
where P represents one statement and Q represents another—for example, Kermit is a frog AND Miss Piggy is an actress. The inputs to the AND operation represent the truth or falseness of the compound statement’s components; the output represents the truth or falseness of the compound statement itself. Since a statement of the form P AND Q is true only when both of its components are true, we conclude that 1 AND 1 should be 1, whereas all other cases should produce an output of 0.
In a similar manner, the OR operation is based on compound statements of the form 
P OR Q
where, again, P represents one statement and Q represents another. Such statements are true when at least one of their components is true, which agrees with the OR operation depicted. There is not a single conjunction in the English language that captures the meaning of the XOR operation. XOR produces an output of 1 (true) when one of its inputs is 1 (true) and the other is 0 (false). For example, a statement of the form P XOR Q means “either P or Q but not both.” (In short, the XOR operation produces an output of 1 when its inputs are different.)
The operation NOT is another Boolean operation. It differs from AND, OR, and XOR because it has only one input. Its output is the opposite of that input; if the input of the operation NOT is true, then the output is false, and vice versa. Thus, if the input of the NOT operation is the truth or falseness of
the statement
Fozzie is a bear.
then the output would represent the truth or falseness of the statement
Fozzie is not a bear.
Main Memory:
For the purpose of storing data, a computer contains a large collection of circuits (such as flip-flops), each capable of storing a single bit. This bit reservoir is known as the machine’s main memory.
Memory Organization:
A computer’s main memory is organized in manageable units called cells, with a typical cell size being eight bits. (A string of eight bits is called a byte. Thus, a typical memory cell has a capacity of one byte.) Small computers used in such household devices as microwave ovens may have main memories consisting of only a few hundred cells, whereas large computers may have billions of cells in their main memories.
Although there is no left or right within a computer, we normally envision the bits within a memory cell as being arranged in a row. The left end of this row is called the high-order end, and the right end is called the low-order end. The leftmost bit is called either the high-order bit or the most significant bit in reference to the fact that if the contents of the cell were interpreted as representing a numeric
value, this bit would be the most significant digit in the number. Similarly, the rightmost bit is referred to as the low-order bit or the least significant bit. Thus we may represent the contents of a byte-size memory cell. To identify individual cells in a computer’s main memory, each cell is assigned a unique “name,” called its address. The system is analogous to the technique of identifying houses in a city by addresses. In the case of memory cells, however, the addresses used are entirely numeric. To be more precise, we envision all the cells being placed in a single row and numbered in this order starting with the value zero. Such an addressing system not only gives us a way of uniquely identifying each cell but also associates an order to the cells, giving us phrases such as “the next cell” or “the previous cell.” 
An important consequence of assigning an order to both the cells in main memory and the bits within each cell is that the entire collection of bits within a computer’s main memory is essentially ordered in one long row. Pieces of this long row can therefore be used to store bit patterns that may be longer than the length of a single cell. In particular, we can still store a string of 16 bits merely by
using two consecutive memory cells.
To complete the main memory of a computer, the circuitry that actually holds the bits is combined with the circuitry required to allow other circuits to store and retrieve data from the memory cells. In this way, other circuits can get data from the memory by electronically asking for the contents of a certain address (called a read operation), or they can record information in the memory by requesting that a certain bit pattern be placed in the cell at a particular address (called a write operation).

Outline of our Study

This text follows a bottom up approach to the study of computer science, beginning with such hands-on topics as computer hardware and leading to the more abstract topics such as algorithm complexity and computability. The result is that our study follows a pattern of building larger and larger abstract tools as our understanding of the subject expands. We begin by considering topics dealing with the design and construction of machines for executing algorithms. In Chapter 1 (Data Storage) we look at how information is encoded and stored within modern computers, and in Chapter 2 Data Manipulation) we investigate the basic internal operation of a simple computer. Although part of this study involves technology, the general theme is technology independent. That is, such topics as digital circuit design, data encoding and compression systems, and computer architecture are relevant over a wide range of technology and promise to remain relevant regardless of the direction of
future technology.
We study the software that controls the overall operation of a computer. This software is called an operating system. It is a computer’s operating system that controls the interface between the machine
and its outside world, protecting the machine and the data stored within from unauthorized access, allowing a computer user to request the execution of various programs, and coordinating the internal activities required to fulfill the user’s requests.
We study how computers are connected to each other to form computer networks and how networks are connected to form internets. This study leads to topics such as network protocols, the Internet’s structure and internal operation, the World Wide Web, and numerous issues of security.
Algorithms introduces the study of algorithms from a more formal perspective. We investigate how algorithms are discovered, identify several fundamental algorithmic structures, develop elementary techniques for representing algorithms, and introduce the subjects of algorithm efficiency
and correctness.
Programming Languages we consider the subject of algorithm representation and the program development process. Here we find that the search for better programming techniques has led to a variety of programming methodologies or paradigms, each with its own set of programming languages. We investigate these paradigms and languages as well as consider issues of grammar
and language translation.
Software Engineering introduces the branch of computer science known as software engineering, which deals with the problems encountered when developing large software systems. The underlying theme is that the design of large software systems is a complex task that embraces problems beyond those of traditional engineering. Thus, the subject of software engineering has become an important field of research within computer science, drawing from such diverse fields as engineering, project management, personnel management, programming language design, and even architecture.
In next two chapters we look at ways data can be organized within a computer system.
Data Abstractions we introduce techniques traditionally used for organizing data in a computer’s main memory and then trace the evolution of data abstraction from the concept of primitives to today’s objectorientedtechniques.
Database Systems we consider methods traditionally used for organizing data in a computer’s mass storage and investigate how extremely large and complex database systems are implemented.
Computer Graphics we explore the subject of graphics and animation, a field that deals with creating and photographing virtual worlds. Based on advancements in the more traditional areas of computer science such as machine architecture, algorithm design, data structures, and software engineering,
the discipline of graphics and animation has seen significant progress and has now blossomed into an exciting, dynamic subject. Moreover, the field exemplifies how various components of computer science combine with other disciplines such as physics, art, and photography to produce striking results.
Artificial Intelligence we learn that in order to develop more useful machines computer science has turned to the study of human intelligence for leadership. The hope is that by understanding how our own minds reason and perceive, researchers will be able to design algorithms that mimic these
processes and thus transfer these capabilities to machines. The result is the area of computer science known as artificial intelligence, which leans heavily on research in such areas as psychology, biology, and linguistics.
We close our study with Theory of Computation by investigating the theoretical foundations of computer science—a subject that allows us to understand the limitations of algorithms (and thus machines). Here we identify some problems that cannot be solved algorithmically (and therefore lie beyond the capabilities of machines) as well as learn that the solutions to many other problems require such enormous time or space that they are also unsolvable from a practical perspective. Thus, it is through this study that we are able to grasp the scope and limitations of algorithmic systems.
In each chapter our goal is to explore to a depth that leads to a true understanding of the subject. We want to develop a working knowledge of computer science—a knowledge that will allow you to understand the technical society in which you live and to provide a foundation from which you can learn on your own as science and technology advance.

The Science of Algorithms

Conditions such as limited data storage capabilities and intricate, time-consuming programming procedures restricted the complexity of the algorithms utilized in early computing machines. However, as these limitations began to disappear, machines were applied to increasingly larger and more complex tasks. As attempts to express the composition of these tasks in algorithmic form began to tax the abilities of the human mind, more and more research efforts were directed toward the study of algorithms and the programming process. It was in this context that the theoretical work of mathematicians began to pay dividends. As a consequence of Gödel’s incompleteness theorem, mathematicians had already been investigating those questions regarding algorithmic processes that advancing technology was now raising. With that, the stage was set for the emergence of a new discipline known as computer science.
Today, computer science has established itself as the science of algorithms. The scope of this science is broad, drawing from such diverse subjects as mathematics, engineering, psychology, biology, business administration, and linguistics. Indeed, researchers in different branches of computer science may have very distinct definitions of the science. For example, a researcher in the field of computer architecture may focus on the task of miniaturizing circuitry and thus view computer science as the advancement and application of technology. But, a researcher in the field of database systems may see computer science as seeking ways to make information systems more useful. And, a researcher in the field of artificial intelligence may regard computer science as the study of intelligence and intelligent behavior. Thus, an introduction to computer science must include a variety of topics, which is a task that we will pursue in the following chapters. In each case, our goal will be to introduce the central ideas in the subject, the current topics of research, and some of the techniques being applied to advance knowledge in the area. With such a variety of topics, it is easy to lose track of the overall picture. We therefore pause to collect our thoughts by identifying some questions that
provide a focus for its study.
• Which problems can be solved by algorithmic processes?
• How can the discovery of algorithms be made easier?
• How can the techniques of representing and communicating algorithms
be improved?
• How can the characteristics of different algorithms be analyzed
and compared?
• How can algorithms be used to manipulate information?
• How can algorithms be applied to produce intelligent behavior?
• How does the application of algorithms affect society?
Note that the theme common to all these questions is the study of algorithms.
Abstraction
             The concept of abstraction so permeates the study of computer science and the design of computer systems that it behooves us to address it in this preliminary chapter. The term abstraction, as we are using it here, refers to the distinction between the external properties of an entity and the details of the entity’s internal composition. It is abstraction that allows us to ignore the internal details of a complex device such as a computer, automobile, or microwave oven and use it as a single, comprehensible unit. Moreover, it is by means of abstraction that such complex systems are designed and manufactured in the first place. Computers, automobiles, and microwave ovens are constructed from components, each of which is constructed from smaller components. Each component represents a level of abstraction at which the use of the component is isolated from the details of the component’s internal composition.
It is by applying abstraction, then, that we are able to construct, analyze, and manage large, complex computer systems, which would be overwhelming if viewed in their entirety at a detailed level. At each level of abstraction, we view the system in terms of components, called abstract tools, whose internal composition we ignore. This allows us to concentrate on how each component interacts with other components at the same level and how the collection as a whole forms a higher-level component. Thus we are able to comprehend the part of the system that is relevant to the task at hand rather than being lost in a sea of details.
We emphasize that abstraction is not limited to science and technology. It is an important simplification technique with which our society has created a lifestyle that would otherwise be impossible. Few of us understand how the various conveniences of daily life are actually implemented. We eat food and wear clothes that we cannot produce by ourselves. We use electrical devices and communication systems without understanding the underlying technology. We use the services of others without knowing the details of their professions. With each new advancement, a small part of society chooses to specialize in its implementation while the rest of us learn to use the results as abstract tools. In this manner, society’s warehouse of abstract tools expands, and society’s ability to progress increases.
Abstraction is a recurring theme in our study. We will learn that computing equipment is constructed in levels of abstract tools. We will also see that the development of large software systems is accomplished in a modular fashion in which each module is used as an abstract tool in larger modules. Moreover, abstraction plays an important role in the task of advancing computer science itself, allowing researchers to focus attention on particular areas within a complex field. In fact, the organization of this text reflects this characteristic of the science. Each chapter, which focuses on a particular area within the science, is often surprisingly independent of the others, yet together the chapters form a comprehensive overview of a vast field of study.

Role Of Algorithem

We begin with the most fundamental concept of computer science—that of an algorithm. Informally, an algorithm is a set of steps that defines how a task is performed. (We will be more precise later in Chapter 5.) For example, there are algorithms for cooking (called recipes), for finding your way through a strange city (more commonly called directions), for operating washing machines (usually displayed on the inside of the washer’s lid or perhaps on the wall of a laundromat), for playing music (expressed in the form of sheet music), and for performing magic tricks (Figure 0.1).
Before a machine such as a computer can perform a task, an algorithm for performing that task must be discovered and represented in a form that is compatible with the machine. A representation of an algorithm is called a program. For the convenience of humans, computer programs are usually printed on paper or displayed on computer screens. For the convenience of machines, programs are encoded in a manner compatible with the technology of the machine. The process of developing a program, encoding it in machine-compatible form, and inserting it into a machine is called programming. Programs, and the algorithms they represent, are collectively referred to as software, in contrast to the
machinery itself, which is known as hardware.
The study of algorithms began as a subject in mathematics. Indeed, the search for algorithms was a significant activity of mathematicians long before the development of today’s computers. The goal was to find a single set of directions that described how all problems of a particular type could be solved. One of the best known examples of this early research is the long division algorithm for finding the quotient of two multiple-digit numbers. Another example is the Euclidean algorithm, discovered by the ancient Greek mathematician Euclid, for finding the greatest common divisor of two positive integers (Figure 0.2).
Once an algorithm for performing a task has been found, the performance of that task no longer requires an understanding of the principles on which the algorithm is based. Instead, the performance of the task is reduced to the process of merely following directions. (We can follow the long division algorithm to find a quotient or the Euclidean algorithm to find a greatest common divisor without understanding why the algorithm works.) In a sense, the intelligence required to solve the problem at hand is encoded in the algorithm.
It is through this ability to capture and convey intelligence (or at least intelligent behavior) by means of algorithms that we are able to build machines that perform useful tasks. Consequently, the level of intelligence displayed by machines is limited by the intelligence that can be conveyed through algorithms. We can construct a machine to perform a task only if an algorithm exists for performing that task. In turn, if no algorithm exists for solving a problem, then the solution of that problem lies beyond the capabilities of machines.
Identifying the limitations of algorithmic capabilities solidified as a subject in mathematics in the 1930s with the publication of Kurt Gödel’s incompleteness theorem. This theorem essentially states that in any mathematical theory encompassing our traditional arithmetic system, there are statements whose truth or falseness cannot be established by algorithmic means. In short, any complete study of our arithmetic system lies beyond the capabilities of algorithmic activities.
History of computing:
This realization shook the foundations of mathematics, and the study of algorithmic capabilities that ensued was the beginning of the field known today as computer science. Indeed, it is the study of algorithms that forms the core of computer science. Today’s computers have an extensive genealogy. One of the earlier computing devices was the abacus. History tells us that it most likely had its roots in ancient China and was used in the early Greek and Roman civilizations. The machine is quite simple, consisting of beads strung on rods that are in turn mounted in a rectangular frame (Figure 0.3). As the beads are moved back and forth on the rods, their positions represent stored values. It is in the positions of the beads that this “computer” represents and stores data. For control of an algorithm’s execution, the machine relies on the human operator. Thus the abacus alone is merely a data storage system; it must be combined with a human to create a complete computational machine.
In the time period after the Middle Ages and before the Modern Era the quest for more sophisticated computing machines was seeded. A few inventors began to experiment with the technology of gears. Among these were Blaise Pascal (1623–1662) of France, Gottfried Wilhelm Leibniz (1646–1716) of Germany, and Charles Babbage (1792–1871) of England. These machines represented data through gear positioning, with data being input mechanically by establishing initial gear positions. Output from Pascal’s and Leibniz’s machines was achieved by observing the final gear positions. Babbage, on the other hand, envisioned machines that would print results of computations on paper so that the possibility of transcription errors would be eliminated. As for the ability to follow an algorithm, we can see a progression of flexibility in these machines. Pascal’s machine was built to perform only addition.
Consequently, the appropriate sequence of steps was embedded into the structure of the machine itself. In a similar manner, Leibniz’s machine had its algorithms firmly embedded in its architecture, although it offered a variety of arithmetic operations from which the operator could select. Babbage’s Difference Engine (of which only a demonstration model was constructed) could be modified to perform a variety of calculations, but his Analytical Engine (the construction for which he never received funding) was designed to read instructions in the form of holes in paper cards. Thus Babbage’s Analytical Engine was programmable. In fact, Augusta Ada Byron (Ada Lovelace), who published a paper in which she demonstrated how Babbage’s Analytical Engine could be programmed to perform various computations, is often identified today as the world’s first programmer.
The idea of communicating an algorithm via holes in paper was not originated by Babbage. He got the idea from Joseph Jacquard (1752–1834), who, in 1801, had developed a weaving loom in which the steps to be performed during the weaving process were determined by patterns of holes in large thick cards made of wood (or cardboard). In this manner, the algorithm followed by the loom could be changed easily to produce different woven designs. Another beneficiary of Jacquard’s idea was Herman Hollerith (1860–1929), who applied the concept of representing information as holes in paper cards to speed up the tabulation process in the 1890 U.S. census. (It was this work by Hollerith that led to the creation of IBM.) Such cards ultimately came to be known as punched cards and survived as a popular means of communicating with computers well into the 1970s. Indeed, the technique lives on today, as witnessed by the voting issues raised in the 2000 U.S. presidential election.
The technology of the time was unable to produce the complex gear-driven machines of Pascal, Leibniz, and Babbage in a financially feasible manner. But with the advances in electronics in the early 1900s, this barrier was overcome. Examples of this progress include the electromechanical machine of George Stibitz, completed in 1940 at Bell Laboratories, and the Mark I, completed in 1944 at Harvard University by Howard Aiken and a group of IBM engineers.

More Problems

Write a program that does the following.The program asks the user to enter a positive integer n.  The program prints a triangle with n rows using the number r to make the characters on row number r. For example, if the user enters 4 for n the output is as follows:
1
22
333
4444

 Code:- 

/*program to make triangle with n rows using the number r to make the
characters on row number r. */
#include<iostream>
using namespace std;
int main()
{
       int n,r,a,b=1;
       cout<<"Enter positive Integer= ";
       cin>>a;
       for(n=0;n<a;n++)
       {
              for(r=0;r<=n;r++)
              {
                     cout<<b;
              }
              cout<<endl;
              b=b+1;
       }
       system("pause");
       return 0;
}
Write a program that prompts the user to input an integer then outputs both the individual digits and the sum of the digits..????
//program to seperate number into its digits and sum of digits.

#include<iostream>
using namespace std;
int main()
{

       int a,b,c,sum=0;
       cout<<"Enter Number"<<endl;
       cin>>a;
       do
       {
              b=a%10;
              c=a/10;
              cout<<b<<" ";
              sum=sum+b;
              a=c;
       }
       while(a!=0);
       cout<<endl;
       cout<<"Sum of Digits= "<<sum<<endl;
       system("pause");
       return 0;
}
Write a program that ask user to input 10 integers and then print the sum of the even and odd integers using loop statements......??????

//program to put ten integer and then sum of the even and odd integers,

#include<iostream>

using namespace std;

int main()

{

       int i,n,Sumeven=0,Sumodd=0;
       cout<<"Enter Ten Numbers:"<<endl;
       for(i=0;i<10;i++)
       {
              cout<<"Enter Number:"<<endl;
              cin>>n;
              if (n%2==0)
              {
              Sumeven=Sumeven+n;
              }
              else if (n%2==1)
              {
                     Sumodd=Sumodd+n;
              }
       }
       cout<<"Sum of even numbers="<<Sumeven<<endl;
       cout<<"Sum of odd numbers="<<Sumodd<<endl;
       system("pause");
       return 0;

}
Input a number from the user and display if the number is a prime number or not...?????

//program to show whether no is prime or not.

#include<iostream>

using namespace std;

int main()

{

       int a,i,flag=0;
       cout <<"Enter positive Integer"<<endl;
       cin>>a;
       for (i=2; i<a; i++)
       {
              if (a%i==0)
              {
                     flag++;
              }
       }
       if (flag==0)
       cout <<"Prime number"<<endl;
       else
              cout<<"Not Prime number"<<endl;
       system("pause");
       return 0;

}
Input four numbers and display the numbers in ascending and descending order......???????????
//program to arrange four numbers in ascending and descending order
#include<iostream>
using namespace std;
int main()
{
       int a,b,c,d,s,t,x,y;
       cout<<"Enter Four Numbers"<<endl;
       cin>>a>>b>>c>>d;
       if(a<b) x=b, y=a;
       else if(b<a) x=a, y=b;
       if(a>b) s=a, t=b;
       else if(b>a) s=a, t=b;
       if(x<c) y=x, x=c;
       else if(y<c) y=c;
       if(s>c) t=s, s=c;
       else if(t>c) t=c;
       if(x<d) y=x, x=d;
       else if(y<d) y=d;
       if(s>d) t=s, s=d;
       else if(t>d) t=d;
       cout<<"Largest Number="<<x<<endl;
       cout<<"2nd Largest Number="<<y<<endl;
       cout<<"Smallest Number="<<s<<endl;
       cout<<"2nd smallest Number="<<t<<endl;
       cout<<"Numbers in ascending order"<<":"<<s<<"  "<<t<<"  "<<y<<"  "<<x<<endl;
       cout<<"Numbers in descending order"<<":"<<x<<"  "<<y<<"  "<<t<<"  "<<s<<endl;
       system("pause");
       return 0;
}
Input a number from the user if the number is divisible by 3 display ‘PADDLE’. If the
number is divisible by 5 display ‘POP’. If the number is divisible by 3 and 5 both display
‘PADDLEPOP’. Else display ‘Not divisible by 3 or 5’.....????????????


//program to display different words on different condition
#include<iostream>
using namespace std;
int main()
{
       int a,b,c,d,e;
       cout<<"Enter Number"<<endl;
       cin>>a;
       b=a%3;
       c=a%5;
       if (b==0)
              cout<<"PADDLE"<<endl;
       if (c==0)
              cout<<"POP"<<endl;
       if (c==0 && b==0)
              cout<<"PADDLEPOP"<<endl;
       if (c!=0 && b!=0)
              cout<<"Not divisible by 3or5"<<endl;
       system("pause");
       return 0;
}
Input five numbers from the user and display the largest and 2nd largest number..?????

//program to find largest number and second largest number from five numbers
#include<iostream>
using namespace std;
int main()
{
       int a,b,c,d,e,x,y;
       cout<<"Enter Five Numbers"<<endl;
       cin>>a>>b>>c>>d>>e;
       if(a<b) x=b, y=a;
       else if(b<a) x=a, y=b;
       if(x<c) y=x, x=c;
       else if(y<c) y=c;
       if(x<d) y=x, x=d;
       else if(y<d) y=d;
       if (x<e) y=x, x=e;
       else if(y<e) y=e;
       cout<<"Largest Number="<<x<<endl;
       cout<<"2nd Largest Number="<<y<<endl;
       system("pause");
       return 0;
}

Development

C++ programs typically go through six phases: edit, preprocess, compile, link, load and execute. The following discussion explains a typical C++ program development environment.
Creating a Program
Phase 1 consists of editing a file with an editor program, normally known simply as an editor . You type a C++ program (typically referred to as source code) using the editor, make any necessary corrections and save the program on a secondary storage device, such as your hard drive. C++ source code file names often end with the .cpp, .cxx, .cc or .C extensions (note that C is in uppercase) which indicate that a file contains C++ source code. See the documentation for your C++ compiler for more information on file-name extensions. C++ software packages for Microsoft Windows such as Microsoft Visual C++ (microsoft.com/express) have editors integrated into the programming environment. You can also use a simple text editor, such as Notepad in Windows, to write your C++ code. 
Preprocessing a C++ Program
In Phase 2, you give the command to compile the program. In a C++ system, a preprocessor program executes automatically before the compiler’s translation phase begins (so we call preprocessing Phase 2 and compiling Phase 3). The C++ preprocessor obeys commands called preprocessor directives, which indicate that certain manipulations are to be performed on the program before compilation. These manipulations usually include other text files to be compiled, and perform various text replacements. The most common preprocessor directives are discussed in the early chapters; a detailed discussion of preprocessor features appears in Appendix E, Preprocessor.
Compiling a C++ Program
In Phase 3, the compiler translates the C++ program into machine-language code—also
referred to as object code.
Linking
Phase 4 is called linking. C++ programs typically contain references to functions and data
defined elsewhere, such as in the standard libraries or in the private libraries of groups of programmers working on a particular project. The object code produced by the C++
compiler typically contains “holes” due to these missing parts. A linker links the object code
with the code for the missing functions to produce an executable program (with no missing
pieces). If the program compiles and links correctly, an executable image is produced.
Loading
Phase 5 is called loading. Before a program can be executed, it must first be placed in memory. This is done by the loader, which takes the executable image from disk and transfers it to memory. Additional components from shared libraries that support the program are also loaded.
Execution
Finally, the computer, under the control of its CPU, executes the program one instruction at a time. Some modern computer architectures can execute several instructions in parallel.
Condition
We now introduce a simple version of C++’s if statement that allows a program to take alternative action based on whether a condition is true or false. If the condition is true, the statement in the body of the if statement is executed. If the condition is false, the body statement is not executed. We’ll see an example shortly. Conditions in if statements can be formed by using the equality operators and relational operators summarized in Fig. 2.12. The relational operators all have the same level of precedence and associate left to right. The equality operators both have the same level of precedence, which is lower than that of the relational operators, and associate left to right. The following example (Fig. 2.13) uses six if statements to compare two numbers input by the user. If the condition in any of these if statements is satisfied, the output statement associated with that if statement is executed.
#include <iostream>
using namespace std;
int main()
{
       int num1,num2;
       cout<<"Enter Two integers:";
       cin>>num1>>num2;
       if(num1==num2)
              cout<<num1<<"=="<<num2<<endl;
       if(num1!=num2)
              cout<<num1<<"!="<<num2<<endl;
       if(num1<num2)
              cout<<num1<<"<"<<num2<<endl;
       if(num1>num2)
              cout<<num1<<">"<<num2<<endl;
       if(num1>=num2)
              cout<<num1<<">="<<num2<<endl;
       if(num1<=num2)
              cout<<num1<<"<="<<num2<<endl;
       system("pause");
       return 0;

}
Loops
Why Is Repetition Needed? 

Repetition allows you to efficiently use variables. Can input, add, and average multiple numbers using a limited number of variables. For example, to add five numbers: Declare a variable for each number, input the numbers and add the variables together. Create a loop that reads a number into a variable and adds it to a variable that contains the sum of the numbers.
                 While Loop(Repetition) Structure:-
The general form of the while statement is:                                        

while is a reserved word.
Statement can be simple or compound. 
Expression acts as a decision maker and is usually a logical expression.
While is a pre-test loop.
Statement is called the body of the loop.
The parentheses are part of the syntax .

Infinite loop: continues to execute endlessly. Avoided by including statements in loop body that assure exit condition is eventually false.
                      
                  Case 1: Counter-Controlled while Loops                  
If you know exactly how many pieces of data need to be read, while loop becomes a counter-controlled loop with loop control variable (LCV) 
#include<iostream.h> 
int main() 
     int total, //sum of grades
     gradeCounter, //number of grades entered 
     grade, //one grade 
     average; //average of grades
                   //initialization phase 
     total = 0; //clear total 
     gradeCounter = 1; //prepare to loop
                  //processing phase 
     while (gradeCounter <= 10) //loop 10 times 
    { 
          cout << "Enter grade: "; //prompt for input
          cin >> grade; //input grade 
          total = total + grade; //add grade total 
          gradeCounter = gradeCounter +1; //increment counter 
    }
                   //termination phase
    average = total/10; //integer division 
    cout << "Class average is " << average <<endl; 
    return 0; //indicate program ended successfully 

}
                         Case 2: Sentinel-Controlled while Loops
Sentinel variable is tested in the condition
Loop ends when sentinel is encountered
            while(score!=-1)
            {
                 cout<<"Good Bye "<<endl;
                 cin>>score;

            }
                            Case 3: Flag-Controlled while loops                           
A flag-controlled while loop uses a bool variable to control the loop.
The flag-controlled while loop takes the form:
boolean done=false;
while(!done)
{
//read some input
   if(condition)
      done=true;
   else
   {
//process input
   }

 }
         do...while Looping (Repetition) Structure  
General form of a do...while:
do
{
statements;
while(condition)
The statement executes first, and then the expression is evaluated.
To avoid an infinite loop, body must contain a statement that makes the expression false.
The statement can be simple or compound.
This loop is post-test loop.

Loop always iterates at least once.
For  Any Problem Contact us on my mail apnapunjab7432@gmail.com                                            
                               For(Loops)
for Looping (Repetition) Structure: -
The general form of the for statement is:
for(initialization;test condition;increment)
{
//Body of loop
Example:-
for(int x=0;x<=10;x++)
{
cout<<x;
}
The initial statement,loop condition, and update statement are called for loop control statements.
Initial statement usually initializes a variable (called the for loop control, or  indexed, variable)

In C++, for is a reserved word. If test is false the first time it is evaluated, the body of the loop will not be executed.The any  update expression can increment or decrements by amount.Variables used in the initialization section should not be modified in the body of the loop.
int sum = 0, num;
for (num = 1; num <= 10; num++)
{   
sum += num;
cout << "Sum of numbers 1 – 10 is ";
cout<< sum << endl;
}