You are on page 1of 11

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

Fundamentals of Object Oriented Programming


CSN- 103

Dr. R. Balasubramanian
Associate Professor
Department of Computer Science and Engineering
Indian Institute of Technology Roorkee
Roorkee 247 667
balarfcs@iitr.ac.in
https://sites.google.com/site/balaiitr/
Pseudo code to find the average of 3
numbers
Declare Num1, Num2, and Num3 as integers

Declare Average as real

Write "Welcome to the program. Enter 3 positive


numbers",

INPUT Num1, Num2, Num3

Average = (Num1 + Num2 +Num3) / 3

Write "The average of three numbers entered is",


Average

Stop
2
Pseudo code for finding area and
circumference of circle
Declare r, c, and ac as real

INPUT "Enter radius of circle:", r

ac = 3.14 * r * r

c = 2 * 3.14 * r

PRINT "Area of circle=", ac

PRINT "Circumference of circle=", c

END. 3
Hello World Program in C++

C++
// Our first program in C++
#include <iostream>
int main()
{
std::cout << "Hello World!";
}

4
Hello World Program in JAVA

public class HelloWorld {


public static void main(String[] args) {
System.out.println("Hello World!");
}

5
Finding Square root of a number in C++

#include <iostream>
#include <math>
int main()
{int x;
cin>>x;
float y=sqrt(x);
cout<<y;
return 0;
}

6
Finding Square root of a number in JAVA

import java.long.Math;
class SquareRoot
{
public static void main(String args[])
{
double x =15;
double y;
y=Math.sqrt(x);
System.out.println(y= +y);
}
}

7
Program to find the addition of Two
Numbers in C++
#include <iostream>
int main()
{ int a, b, c;
cout << "Enter two numbers to add\n";
cin >> a >> b;
c = a + b;
cout <<"Sum of entered numbers = " << c <<
endl;
return 0;
}

8
import java.util.Scanner;
class AddNumbers
{
public static void main(String args[])
{
int a, b, c;
System.out.println("Enter two integers to calculate
their sum ");
Scanner in = new Scanner(System.in);
//System.in as InputStream
a = in.nextInt();
b = in.nextInt();
c = a + b;
System.out.println("Sum of entered integers = "+c);
}
} 9
More on Scanner Class

http://www.cs.utexas.edu/users/ndale/Scanner.html

10
11

You might also like