Posts

Showing posts from October, 2020

Introduction to C++

Introduction to C++ 1. C++ is a general purpose,case-sensitive, free-form programming language that0 supports object-oriented,procedural and generic programming. 2. C++ is a middle-level language,as it encapsulates both high and low level language features. 3. C++ was developed by Bjarne Stroustrup of AT&T Bell Laboratories in the early 1980's, and is based on the C language. The "++" is a syntactic construct used in C (to increment a variable), and C++ is intended as an incremental improvement of C. Most of C is a subset of C++, so that most C programs can be compiled (i.e. converted into a series of low-level instructions that the computer can execute directly) using a C++ compiler. C++ is a superset of C, and that virtually any legal C program is a legal C++ program C++ is an Object-Oriented Programming (OOP) Language. It was developed by “Bjarne Stroustrup” in 1980. Bjarne Stroustrup wants  to develop a language that support object-oriented programming features wi...

Java vs C++

S No. Parameters C++ Java 1. Platform Dependency C++ is platform dependent language.    Java is platform independent language. 2. Platform Philosophy Write once, compile anywhere (WOCA).    Write once, run anywhere / everywhere (WORA / WORE). 3. Developer Bjarne Stroustrup , 1980 James Gosling, Patrick Naughton, Chris Warth, Ed Frank & Mike Sheridan at Sun Microsystems, in 1991. 4. Original Name Originally named as "C with Classes" by Bjarne Stroustrup, renamed to "C++" (indicating an increment to C) which is proposed by Rrick Mascitti in 1983. Originally named as "Oak" by James Gosling, renamed to "Java" 1995. 5. Evolution C++ is a superset of C. C++ is evolved from C & simula67. Java is neither a superset nor a subset of C & C++. It takes some features from C & C++ and also includes some new features too. 6. Language level C++ is a middle-level language. Java is a high-level language. 7. Extensions C++ files have extension .cpp ...

SUM SERIES

Image
          SUM OF SERIES         1.SUM OF SERIES 1+1/2+1/3+1....1/N        #include <stdio.h> main () { int i , n ; float sum = 0 ; printf ( "Enter value of n\n" ); scanf ( "%d" ,& n ); for ( i = 1 ; i <= n ; i ++) { sum +=( float ) 1 / i ; } printf ( "The value of\n" ); for ( i = 1 ; i <= n ; i ++) { if ( i < n ) { printf ( "1/%d+ " , i ); } else { printf ( "1/%d= " , i ); } } printf ( "%f\n" , sum ); } •Output Enter value of n 8 The value of 1/1+ 1/2+ 1/3+ 1/4+ 1/5+ 1/6+ 1/7+ 1/8= 2.717857 2.SUM OF SERIES 1/1!+1/2!+1/3!+1....+N /N! main() { int i,n; float sum=0; printf("Enter value of n\n"); scanf("%d",&n); for(i=1;i&lt;=n;i++) {  sum+=(float)i/factorial(i); } printf("The value of\n"); for(i=1;i&lt;=n;i++) {  if(i&lt;n)  {   printf("%d/%d!+ ",i,i);  }  else  {   printf("%d/%d!= ",i,i);  } } pri...

SWITCH PROGRAMME

Image
      ☆SWITCH PROGRAMME LIST☆ What is a switch Statement in C? The switch case statement is used when we have multiple options and we need to perform a different task for each option.when the variable being switched on is equal to a case,the statements following that case will execute until a break statement is reached. When a break statement is reached the switch terminates,and the flow of control jumps to the next line after the switch statement.Not every case needs to contain a break .if no break appears , the flow of control will fall through to subsequent cases until a break is reached.  The if..else..if ladder allows you to execute a block code among many alternatives. If you are checking on the value of a single variable in if...else Ladder , it is better to use switch statement. The switch statement is often faster than nested if...else (not always). Also, the syntax of switch statement is cleaner and easy to understand. The syntax of switch...case: When a ca...

DO WHILE LOOP

  do...while loop: The do..while loop is similar to the while loop with one important difference. The body of do...while loop is executed at least once. Only then, the test expression is evaluated. The syntax of the do...while loop is: do { // statements inside the body of the loop }while(test expression) How do...while loop works?? The body of do...while loop is executed once. Only then, the test expression is evaluated. If the test expression is true, the body of the loop is executed again and the test expression is evaluated. This process goes on until the test expression becomes false. If the test expression is false, the loop ends. Example : #include <stdio.h> void main () { int number, sum = 0 ; // the body of the loop is executed at least once do { printf( "Enter a number: " ); scanf( "%d" , &number); sum += number; } while (number != 0 ); printf( "Sum = %d" ,sum)...

FOR LOOP

Image
  ☆  For LOOP PROGRAMME : The syntax of the for loop is: for (initializationStatement; testExpression; updateStatement) { // stastatements inside the body of loop } How for loop works? The initialization statement is executed only once. Then, the test expression is evaluated. If the test expression is evaluated to false, the for loop is terminated. However, if the test expression is evaluated to true, statements inside the body of for loop are executed, and the update expression is updated. Again the test expression is evaluated. This process goes on until the test expression is false. When the test expression is false, the loop terminates. Example : #include <stdio.h> void main () { int i; for (i = 1 ; i < 11 ; ++i) { printf( "%d " , i); } } Output :1 2 3 4 5 6 7 8 9 10 Now Let's iterate above example i is initialized to 1. The test expression i < 11 is evaluated. Since 1 less than 11 is true, the body of for loop...

WHILE LOOP

Image
 The syntax of the while loop is: while (test expression) { // statements inside the body of the loop } How while loop works?? The while loop evaluates the test expression inside the parenthesis (). If the test expression is true, statements inside the body of while loop are executed. Then, the test expression is evaluated again. The process goes on until the test expression is evaluated to false. If the test expression is false, the loop terminates (ends). Example : #include <stdio.h> void main() {     int i = 1;     while (i <= 5)     {         printf(" %d ", i);         ++i;     } } Output : 1 2 3 4 5 Now Let's iterate above example Here, we have initialized i to 1. When i is 1, the test expression i <= 5 is true. Hence, the body of the while loop is executed. This prints 1 on the screen and the value of i is ...

IF ELES LOOP

Image
   Conditional statements in c programming :   (if ,if-else,nested if) What is a Conditional Statement in C? Conditional Statements in C programming are used to make decisions based on the conditions. Conditional statements execute sequentially when there is no condition around the statements. If you put some condition for a block of statements, the execution flow may change based on the result evaluated by the condition. This process is called decision making in 'C.' In 'C' programming conditional statements are possible with the help of the following two constructs: 1. If statement 2. If-else statement It is also called as branching as a program decides which statement to execute based on the result of the evaluated condition.                          ■IF PROGRAMME LIST■ We use if statement to check a condition and if the condition is true, we run a if- block statement else we process another block of stat...

structure

Image
/* This program prints Hello on Console Screen */ #include<stdio.h> void main() {      printf("hello world"); } Comments: In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. Comments are statements that are not executed by the compiler and interpreter.  All the comments will be put inside /*...*/ as given in the example above. A comment can span through multiple lines. #include<stdio.h> These commands tells the compiler to do preprocessing before doing actual compilation. Like #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation. void main() This is the main function, which is the default entry point for every C program and the void in front of it indicates that it does not return a value. {...} Curly braces which shows how much the main() function has its scope. printf("hello world"); The C Pro...
Statement : The syntax of the if statement in C programming is: if (test expression) { // statements to be executed if the test expression is true } How if statement works? If the test expression is evaluated to true, statements inside the body of if are executed. If the test expression is evaluated to false, statements inside the body of if are not executed. Example : #include <stdio.h> void main() {     int number;     printf("Enter an integer: ");     scanf("%d", &number);     // true if number is greater than 0     if (number > 0)     {         printf("You entered %d.\n", number);     }     printf("Sign of Good Learner",); } First run: Enter an integer: 20 You entered 20 Sign of Good Learner Second run: Enter an integer: -10 Sign of Good Learner if...else Statement : The sy...
 A Switch statement  allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for switch case.  When you want to solve multiple option type problems, where one value id associated  with each option and you need to choose only one at a time, then switch statement is used. What is a switch Statement in C? The switch case statement is used when we have multiple options and we need to perform a different task for each option.when the variable being switched on is equal to a case,the statements following that case will execute until a break statement is reached. When a break statement is reached the switch terminates,and the flow of control jumps to the next line after the switch statement.Not every case needs to contain a break .if no break appears , the flow of control will fall through to subsequent cases until a break is reached.  The if..else..if ladder allows you to execute ...

GRAPHICS

Image
                       1.CIRCLE  #include<stdio.h> #include<graphics.h> #include<conio.h> int main() { int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\tc\\bgi"); //initialization of graphic mode circle(150,200,50); getch(); closegraph();//closing of graphic mode return 0; } •Output 2.LINE #include<stdio.h> #include<graphics.h> #include<conio.h> int main() { int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\tc\\bgi"); //initialization of graphic mode line(150,150,250,250); getch(); closegraph();//closing of graphic mode return 0; } •Output 3.RECTANGLE #include<stdio.h> #include<graphics.h> #include<conio.h> int main() { int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\tc\\bgi"); //initialization of graphic mode rectangle(150,150,350,250); ...

FILE HANDLING

10.1.1 File Pointers It is not enough to just display the data on the screen. We need to save it because memory is volatile and its contents would be lost once program terminated, so if we need some data again there are two ways one is retype via keyboard to assign it to particular variable, and other is regenerate it via programmatically both options are tedious. At such time it becomes necessary to store the data in a manner that can be later retrieved and displayed either in part or in whole. This medium is usually a ''file'' on the disk. Introduction to file Until now we have been using the functions such as scanf,printf, getch, putch etc to read and write data on the variable and arrays for storing data inside the programs. But this approach poses the following programs. 1. The data is lost when program terminated or variable goes out of scope. 2. Difficulty to use large volume of data. We can overcome these problems by storing data on secondary devices such as Har...