Looking for a Tutor Near You?

Post Learning Requirement » x
Ask a Question
x
x

Direction

x

Ask a Question

x

Hire a Tutor

Notes On Programming

C ++ programming notes

Roshin S / Sharjah

2 years of teaching experience

Qualification: Masters in computer science

Teaches: IELTS, OET, GED, GATE, Computer Science, English, Science, MS Office, Web Development, C Language, C++, Computer, Maths

Contact this Tutor
  1. What is a Program? A program is a set of instructions that are given to the computer to execute. It allows the computer to perform a specific task. Each and every program has a unique function to do. These programs are stored in the memory and are run when it is necessary. Every program is written in programming languages such as C, C++, Java etc., these programs are run using a compiler. What is a Software? A software is a set of programs or instructions given to a computer system. It is a collection of programs that performs a function. It controls the working of a computer and manages all the components. What are the Programming Fundamentals? 1. Variables Variables are used to store information. They are "containers that hold information" for later use. For example, when you visit a website and a window pops up prompting you to enter in your email address, that's a variable. The programmer who coded this window could have named the variable "CustomerEmail," so that when you submit your email address, it will be stored in the "CustomerEmail" variable. 2. Basic Syntax Every programming language has a syntax—a set of rules that define particular layouts of letters and symbols—so you 'Il need to know the basic syntax of the language you're learning while coding. For example, once you've declared a variable, you can assign a syntax to it. If you declare a variable named "greet," you can assign the value "Hi there" to it. That way, wherever you include the "greet" variable, it will show up as "Hi there" to the end recipient.
  2. 3. Data Structures When a large amount of related data is involved, programmers create what are called data structures. Going back to our "CustomerEmail" example of variables, the programmer would create a data structure to hold each related variable—in this case, the data structure would be a list containing customer email addresses. Rather than creating a different variable for every customer's email, you can use the same one ("CustomerEmail") and store them together in a list. 4. Control Structures Control structures are work flows created by programmers. They are "commands that allow a program to "decide" to take one direction or another," meaning they define a process in your code so that the computer understands where to go next. 5. Debugging Debugging is a vital part of programming. It's a process that involves identifying existing and potential problems and errors, finding the source of those problems, and correcting them. Importance of Learning Programming Languages? We are moving towards the world of automation and coding is a part of this. A programming language can bring you to an automated world where humans control the interaction with the machine. And humans are completely able to make machines work accurately. Firstly, there is no pressure to learn a program. But there is no harm also, in fact, learning a programming language can trigger your nerves and boost your brain. Learning a programming language can help a lot, especially if you are a kid. There are lots of reasons why you should learn programming. Here is the list below of all benefits you can get while learning to program: • It makes you think differently
  3. You will become more logical Helps to solve problems Learn from previous mistakes Build never give up attitude Expand creativity Ability to adopt advanced technology Increase confidence, be ready to take on challenges, etc. Types of programming languages A wide range of programming languages lists out there. But, in general, there are only two types of programming languages. Those are — Low-Level Language: Low-level languages are actually machine languages and assembly languages. These are used for intersecting with computer machines. It only understands binary digits Os and Is. High-Level Language: High-level languages are very popular because using this language developers are making software. Such popular high-level languages are C#, Java, Python, PHP, etc. C Language C is a programming language developed at AT & T 's Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. In the late seventies C began to replace the more familiar languages of that time like PL/1, ALGOL, etc. Structure of C Language program main function( ) Local variables; Statements;
  4. User defined function Comment line It indicates the purpose of the program. It is represented as / *. Comment line is used for increasing the readability of the program. It is useful in explaining the program and generally used for documentation. It is enclosed within the decimeters. Comment line can be single or multiple line but should not be nested. It can be anywhere in the program except inside string constant & character constant. Global Declaration: This is the section where variable are declared globally so that it can be access by all the functions used in the program. And it is generally declared outside the function : main() It is the user defined function and every function has one main() function from where actually program is started and it is encloses within the pair of curly braces. The main( ) function can be anywhere in the program but in general practice it is placed in the first position. Syntax : main() The main( ) function return value when it declared by data type as int main( ) { return O; The main function does not return any value when void (means null/empty) as void main(void ) or
  5. void main() printf ("C language"); Output: C language The program execution start with opening braces and end with closing brace. And in between the two braces declaration part as well as executable part is mentioned. And at the end of each line, the semi-colon is given which indicates statement termination. / *First c program with return statement*/ #include int main (void) printf ("welcome to c Programming language.\n"); return O; Output: welcome to c programming language. / * Simple program to add two numbers. ......*/ #include int main (void) int VI, v2, sum; //vl,v2,sum are variables and int is data type declared VI v2 = 25; sum = VI + v2; printf ("The sum of %i and %i VI, v2, sum); return O; Output: The sum of 150 and 25 is=175 Character set = 150; A character denotes any alphabet, digit or special symbol used to represent information. The alphabets, numbers and special symbols when properly combined form constants, variables and keywords. Identifiers Identifiers are user defined word used to name of entities like variables, arrays, functions, structures etc. Rules for naming identifiers are:
  6. l) name should only consists of alphabets (both upper and lower case), digits and underscore (_) sign. 2) first characters should be alphabet or underscore 3) name should not be a keyword 4) since C is a case sensitive, the upper case and lower case considered differently, for example code, Code, CODE etc. are different identifiers. 5) identifiers are generally given in some meaningful name such as value, net_salary, age, data etc. An identifier name may be long, some implementation recognizes only first eight characters, most recognize 31 characters. Kevword There are certain words reserved for doing specific task, these words are known as reserved word or keywords. These words are predefined and always written in lower case or small letter. These keywords cannot be used as a variable name as it assigned with fixed meaning. Some examples are int, short, signed, unsigned, default, volatile, float, long, double, break, continue, typedef, static,do, for, union, return, while, do, extern, register, enum, case, goto, struct,char, auto, const etc. Data tvpes Data types refer to an extensive system used for declaring variables or functions of different types before its use. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. The value of a variable can be changed any time. Variables Variable is a data name which is used to store some data value or symbolic names for storing program computations and results. The value of the variable can be change during the execution. The rule for naming the variables is same as the naming identifier. Before used in the program it must be declared. Declaration of variables specify its name, data types and range of the value that variables can store depends upon its data types. Syntax: int a; char c;
  7. float f; Variable initialization When we assign any initial value to variable during the declaration, is called initialization of variables. When variable is declared but contain undefined value then it is called garbage value. The variable is initialized with the assignment operator such as Data type variable name=constant; Example: int a=20; Or int a; a-=20; Q l) Write a program to check whether given number is positive or not #include void main() int num; printf("Enter a number: \n"); scanf("%d", &num); if (num > O) printf("%d is a positive number , num); else if (num < O) printf("%d is a negative number \n", num); else printf("() is neither positive nor negative"); Q2) C Program to find greatest of three numbers #include int main() { float numl, num2, num3;
  8. printf("Enter first number: "); scanf("%f", &numl); printf("Enter second number: "); scanf("%f", &num2); printf("Enter third number: "); scanf("%f", &num3); // if num I is greater than num2 & num3, num I is the largest if (num I num2 && numl num3) printf("%f is the largest number.", num l); // if num2 is greater than num I & num3, num2 is the largest if (num2 numl && num2 num3) printf("%f is the largest number.", num2); // if num3 is greater than numl & num2, num3 is the largest if (num3 numl && num3 num2) printf("%f is the largest number.", num3); return O; Q3) Program to find sum of natural numbers using for loop #include int main() int n, count, sum = O; printf("Enter the value of n(positive integer): " scanf("%d",&n); for(count=l; count n; count+) sum = sum + count; printf("Sum of first %d natural numbers is: %d" ,n, sum); retum O;
  9. Q4) C Program to display Fibonacci series int main() int count, first_term = O, second _ term = I , next_term, i; //Ask user to input number of terms printf("Enter the number of terms:\n"); scanf("%d",&count); printf("First %d terms of Fibonacci ,count); for (i = O; i < count ; i++ ) if (i I ) next term = i; else — first_term + second_term; next term — first term = second term; second _ term = next_term; printf(" " ,next_term); return O; Functions A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division is such that each function performs a specific task.
  10. A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function. DEFINING A FUNCTION The general form of a function definition in C programming language is as follows return_type function _ name( parameter list ) { body of the function A function definition in C programming consists of a function header and a function body. Here are all the parts of a function Return Type — A function may return a value. The return _ type is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the return _ type is the keyword void. Function Name — This is the actual name of the function. The function name and the parameter list together constitute the function signature. Parameters — A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters. Function Body — The function body contains a collection of statements that define what the function does. int max(int numl, int num2); Parameter names are not important in function declaration only their type is required, so the following is also a valid declaration int max(int, int); Function declaration is required when you define a function in one source file and you call that function in another file. In such case, you should declare the function at the top of the file calling the function.
  11. Call by value This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument. Call by reference This method copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. This means that changes made to the parameter affect the argument. C++ Programming