Docsity

Programming Fundamentals C++, Summaries of Computer science

Partial preview of the text

Download Programming Fundamentals C++ and more Summaries Computer science in PDF only on Docsity!

Course Outline

It is a basic course for the students of class 8th^ to class 12th. This course is developed under Dev IEO the IT company and community and Doc By IEO. This course is eligible under the permissions of Development By IEO. This course cover basic concepts of coding in C++ programming language.

  • History of C++ Programming Language. Since its intro duction in the early 1980s, C++ has been used extensively and has a long history. Bjarne Stroustrup created it as an addition to the C++ programming language. The C language, invented in the 1970s by Dennis Ritchie, is where the history of C++ begins. Because of its ease of use and effectiveness, C quickly gained popularity and was widely used to create operating systems and other types of low-level software. Danish computer scientist Bjarne Stroustrup recognized an opportunity to improve C by adding new capabilities that would increase its power and flexibility. Stroustrup began developing what he dubbed "C with Classes" in 1979. He introduced the idea of classes, enabling developers to build reusable code modules with data and functionalities. Complex programmers could now be organized and managed more easily thanks to this method, known as object-oriented programming language. Stroustrup kept developing and broadening C using Classes throughout time. The language was renamed

C++ in 1983 to better represent its development. The "++" sign in programming denotes an advancement, implying that C++ was superior than C. As a strong and adaptable tool for creating a variety of applications, C++ became more and more popular in the 1990s. In disciplines including game development, scientific computing, and system programming, it rose to prominence in particular. New additions and modifications to the language were made throughout time as it continued to change. The first official C++ language standard, dubbed C++98 by the International Organization for Standardization (ISO), was published in 1998. By establishing a standard, C++ code may be made to run on a variety of systems and compilers. Since then, the C++ standard has undergone a number of revisions, including C++03, C++11, C++14, C++17, and C++20. Each version added new functions and enhancements that made C++ more flexible, effective, and secure.

  • Basic Operations In C++, there are several basic operations that you can perform. Here are nine common operations: 1: Arithmetic Operations: These include addition (+), subtraction (-), multiplication (*), division (/), and modulo or remainder (%). 2: Assignment: The assignment operator (=) is used to assign a value to a variable. For example, int x = 5; assigns the value 5 to the variable x. 3: Increment and Decrement: The increment operator (++) is used to increase the value of a variable by 1, while the decrement operator (--) decreases the value by 1. For example, x++; or x--; modifies the value of x according. 8: Input and Output Operations: C++ provides the cin and cout objects for reading input from the user and printing output to the console. These operations allow you to interact with the user and display information. 9: Function Calls: C++ allows you to define functions and call them within your program. Functions encapsulate a block of code and can

be called multiple times with different inputs, enabling code reuse and modular programming. These are some of the fundamental operations in C++. However, C++ is a rich language with many more advanced operations and features that you can explore as you dive deeper into the language. 4: Comparison Operations: These include equality (==), inequality (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=). These operations are used to compare values and return a Boolean result (true or false). 5: Logical Operations: The logical operators include logical AND (&&), logical OR (||), and logical NOT (!). These operators are used to combine or negate Boolean expressions and evaluate the resulting Boolean value. 6: Conditional Statements: C++ provides conditional statements such as if, if-else, and switch. These statements allow you to control the flow of execution based on certain conditions. 7: Looping: C++ offers different types of loops like the for loop, while loop, and do-while loop. These loops allow you to execute a

  • Data Types. In C++, data types are used to determine the kind of information that can be stored in a variable. These data types help us organize and work with different types of data in our programs. Here are some commonly used data types in C++:
  1. Integer (int): This data type is used to hold entire integers without any decimal places, both positive and negative. The integer data type, for instance, may be used to record information such as the number of pages in a book.
  2. Floating-point (float, double): Numbers with decimal places are stored using floating-point data types. Float and double both provide the storage of floating-point values with different levels of accuracy. Either float or double can be used to hold a book's price, which may contain decimal values.
  3. Character (char): Individual characters, such as letters, integers, or symbols, are stored using the character data type. If you wish to save a book's title, for instance, you may use the char data type to save each character.
  4. String: The string data type is used to hold a series of characters as opposed to the char data type, which only

saves a single character. It is perfect for keeping individual words, phrases, or sentences. The author's name or the category of a book can both be stored using the string data type.

  1. Boolean (bool): A Boolean data type may hold either true or false and reflects a logical value. It is frequently used to describe circumstances or to denote the status of something. A Boolean data type can be used, for instance, to indicate whether a book is available (true) or borrowed (false). These are just a few examples of data types in C++. Each data type has its own purpose and range of values it can store. By choosing the appropriate data type for each variable, you can efficiently store and manipulate different types of data in your programs. In C++, data types are used to determine the kind of information that can be stored in a variable. These data types help us organize and work with different types of data in our programs. Here are some commonly used data types in C++: These are just a few examples of data types in C++. Each data type has its own purpose and range of values it can store. By choosing the appropriate data type for each variable, you can efficiently store and manipulate different types of data in your programs. In C++, data types are used to determine the kind of information that can be stored in a variable. These data types help us organize and
  • Loops. In C++, loops are used to repeat a block of code Multiple times. They are helpful when we want to Perform the same actions on a set of data or execute a certain task repeatedly. Here are some commonly used loops in C++:
  1. While loop: while a certain condition is true, the while loop continually runs a block of code. THE CODE inside the loop is performed once the Condition has been checked to see if it evaluates To true. Up till the condition is false, the loop is In motion. A while loop, for instance, may be used to read and analyze every chapter of a book until there are none left to read.
  2. For loop: a piece of code is run a certain Number of times using the for loop. Initialization, condition, and increment/decrement are the three elements that make up this structure. Before determining if the condition is true, the loop initializes a counter variable. Upon confirmation, the loop's code is run, and the counter is either increased or decreased at the end of each iteration. When you are certain of how often you want to repeat a process, this loop is helpful.

The page numbers of a book from the first page to the last, for instance, may be printed using a for loop.

  1. Do-while loop: this loop is comparable to the While loop but ensures that the code block is run At least once even if the condition is false. The Code inside the loop is first run, and then the Condition is checked. The loop keeps running if The condition is true. Before requesting the Reader to review a book again, you can ask them to do so at least once using a do-while loop. Loops are powerful tools for automating repetitive tasks in programming. By using the appropriate loop, you can efficiently process and manipulate data.

Arrays can be initialized at the time of declaration, specifying the values to be stored in each element. Additionally, we can determine the size of an array based on our requirements. Let's see an example: Example 2: Array Initialization. In this example, we declare and initialize an array called days of week with the values 1 to 7 using an initializer list. We then use a loop to access and print each element of the array. Common Operations with Arrays: Arrays offer several useful operations that help us manipulate and analyze data efficiently. Let's explore some common operations: In this example, we declare and initialize an array called days Of Week with the values 1 to 7 using an initializer list. We then use a loop to access and print each element of the array.

Common Operations with Arrays: Arrays offer several useful operations that help us manipulate and analyze data efficiently. Let's explore some common operations. Example 3: Mathematical Operations with Arrays.

var sum = a + b; return sum; } Explanation: We define a function named addNumbers that accepts two arguments, a and b. Inside the function, we declare a variable sum and assign the sum of a and b to it. Finally, we use the return keyword to send the value of sum back to the caller. Calling a Function: To use a function, we need to call it by its name and pass the required arguments. Example 2: Calling the Addition Function var result = addNumbers(5, 3); console.log(result); // Output: 8 Explanation: We call the addNumbers function with the arguments 5 and

The function computes the sum of 5 and 3, which is 8. The value of 8 is stored in the variable result. Finally, we print the value of result using the console.log() function Return Statement:

Functions can return a value using the return statement. This allows us to capture the result of the function and use it elsewhere in the program. Example 3: Function with Multiple Return Statements function checkEvenOdd(num) { if (num % 2 === 0) { return "Even"; } else { return "Odd"; } } Explanation: The checkEvenOdd function takes a number as input. It checks if the number is divisible by 2 (i.e., even) using the modulo operator %. If the number is even, it returns the string "Even". Otherwise, it returns the string "Odd". These examples provide a basic understanding of functions in programming. By using functions, students can write modular and reusable code, making their programs more efficient and easier to maintain.