OOP USING C PLUS PLUS


In Amity, the Labs have Turbo C++ running on a Linux OS with the help of a DOS BOX.

I'd rather learn C++ using the gcc IDE, but have to use Turbo C++ IDE for exams.
Therefore, I have installed TC alongside DevC++ (gcc). 

Even ideone.com is no longer useful. [ My Online Notepad : Shrib.com ]

Decided to upload the programs later in a PDF file. 

0 Compare Borland (TurboC) & gcc++ (Linux) compiler

posted Nov 10, 2011, 6:05 AM by Neil Mathew   [ updated Nov 10, 2011, 6:09 AM ]

Compare using a program which finds the reverse of a number:


 Borland     gcc++
#include <iostream.h>
 
void main()
{
int rev=0,digit;
int num,n;
 
cout<<"\n Enter the Number:";
cin>>num;
 
n=num;
 
do
{
digit=n%10;
 
rev=rev*10 + digit;
 
n=n/10;
}
while(n>0);
 
cout<<"\n Reverse: "<<rev
} 
 #include <iostream>
 
using namespace std;
 
int main() //Must be int
{
int rev=0,digit;
int num,n;
 
cout<<"\n Enter the Number:";
cin>>num;
 
n=num;
 
do
{
digit=n%10;
 
rev=rev*10 + digit;
 
n=n/10;
}
while(n>0);
 
cout<<"\n Reverse: "<<rev;
 
return 2
}   

Q2. WAP to swap two numbers using classes.

posted Jul 28, 2011, 9:14 AM by Neil Mathew   [ updated Jul 28, 2011, 9:33 AM ]


SOURCE CODE:


#include<iostream.h>
#include<conio.h>



class Swap
{
int a;
int b;

public:

void Get()
{
cout<<"\n Enter Number A: ";
cin>>a;
cout<<"\n Enter Number B: ";
cin>>b;
}


void Swapper()
{
cout<<"\n\n Swapping... ";
int temp;
temp=a;
a=b;
b=temp;
}

void Show()
{
cout<<"\n Number A: "<<a;
cout<<"\n Number B: "<<b;
}

};

void main()
{
clrscr();

Swap s1;

s1.Get();
s1.Swapper();
s1.Show();

getch();

}


OUTPUT:



Q1. WAP, using classes, to get marks of 5 subjects and find average.

posted Jul 28, 2011, 8:28 AM by Neil Mathew   [ updated Jul 28, 2011, 9:17 AM ]


SOURCE CODE:

#include<iostream.h>
#include<conio.h>

class Report
{
int sub[5];
float avg;

public:
void Add();
void Avg();
void Show();
}ob;


void Report::Add()
{
cout<<"\n Enter the 5 subject marks: ";
for(int i=0; i<5; i++)
cin>>sub[i];
}

void Report::Avg()
{
avg=0;
for(int i=0; i<5; i++)
avg+=sub[i];

avg/=5;
}

void Report::Show()
{
cout<<"\n The Average marks are: "<<avg;
}

void main()
{        clrscr();

ob.Add();
ob.Avg();
ob.Show();

getch();

};



OUTPUT:



0 Keyboard Shortcuts.

posted Jul 28, 2011, 7:50 AM by Neil Mathew   [ updated Jul 28, 2011, 8:28 AM ]


Turbo C++ Shortcuts:


Ctrl+INS : Copy.

Shift+INS : Paste.

F10 : Open Menu.
 (Then use TAB/Arrow Keys and Enter to move around)

F2 : Save Program.

F3 : Open Program.

Alt+F9 : Compile program.

Alt+F5 : Show Output.

Crtl+F9 :

Under Turbo C++:     Runs program.
Under DOSBOX:       Terminate itself. 

Now there are a few differences between what I should expect based on info from the Net,
 and how it actually turns out in our amity labs. 

CTRL + F9 - Displays a Black Screen with a blinking cursor. 
No keys work, and CTRL+ALT+DEL restarts the PC.

However, I noticed CTRL + F (1-12) switches between various windows within DOSBox. 
To return to Turbo C++ when screen shows up blank, click CTRL + F7.


Other Info:

[ 1 ] To minimize the DOSBox, and return to Linux:

CTRL + F1 : Shows the keymapper configuration screen

But, it takes you out of the application and into Linux OS. 
When you're done, just click exit on the screen, and it returns to Turbo C++


[ 2 ] To find the .CPP Source Code on Linux,

File System > home > student > program > dos


[ 3 ] How to navigate within Turbo C++ when the mouse pointer no longer works.

F10 : Open Menu.

 Then use Arrow keys and Enter to choose your menu item.


Q0 First Class. 5 Basic Questions.

posted Jul 19, 2011, 11:05 AM by Neil Mathew   [ updated Nov 10, 2011, 5:59 AM ]


WAP to find multiplication tables using functions.


SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream.h> 
// Unlike C, <stdio.h> is insufficient. (acc to DevC++)
#include <conio.h> 
// for getch(), not accepted in gcc (but accepted in DevC++)
 
void Table(int n)
{
int i=1; 
for(; i<=12; i++)
cout<<endl<<i<<" x "<<n<<" = "<<i*n;
}
 
int main() //gcc compiler requires int
{
int num;
printf("\n Enter number: ");
cin>>num;
 
printf("\n Table : \n");
Table(num);
 
getch();
return 0;
}

INPUT/OUTPUT:


 Enter number: 45

 Table :

1 x 45 = 45
2 x 45 = 90
3 x 45 = 135
4 x 45 = 180
5 x 45 = 225
6 x 45 = 270
7 x 45 = 315
8 x 45 = 360
9 x 45 = 405
10 x 45 = 450
11 x 45 = 495
12 x 45 = 540




WAP to make number half-pyramid 1:


1
1 2
1 2 3 
1 2 3 4
1 2 3 4 5

SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
#include<conio.h>
 
int main()
{
int i,j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
printf("%d ",j);
}
printf("\n");
}
 
getch();
return 1; 
}
 

INPUT/OUTPUT:


1
1 2
1 2 3
1 2 3 4
1 2 3 4 5





WAP to make number half-pyramid 2:


1
1 1
1 1 1 
1 1 1 1
1 1 1 1 1

SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
#include<conio.h>
 
int main()
{
int i,j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
printf("1 ");
}
printf("\n");
}
 
getch();
return 1;
}

INPUT/OUTPUT:


1
1 1
1 1 1
1 1 1 1
1 1 1 1 1




WAP to use switch case to find
(i) number is odd or even (ii) largest no among three entered


SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream.h>
#include <conio.h>
 
 
int main()
{
int ch,num1, num2, num3;
 
cout<<"\n MENU: \n";
cout<<"\n 1. Even/Odd ";
cout<<"\n 2. Largest of 3 ";
cout<<"\n Your Choice: ";
cin>>ch;
 
switch(ch)
{
case 1: 
cout<<"\n Enter number: ";
cin>>num1;
 
if(num1%2==0)
cout<<"\n Number is Even. ";
else
cout<<"\n Number is Odd. ";
break;
 
case 2:
cout<<"\n Enter First number: ";
cin>>num1;
 
cout<<"\n Enter Second number: ";
cin>>num2;
 
cout<<"\n Enter Third number: ";
cin>>num3;
 
if(num1>=num2 && num1>=num3)
cout<<"\n"<<num1<<" is greatest. ";
else if( num2>=num1 && num2>=num3)
cout<<"\n"<<num2<<" is greatest. ";
else
cout<<"\n"<<num3<<" is greatest. ";
break;
 
}
getch();
}
 
 


INPUT/OUTPUT:


 MENU:

 1. Even/Odd
 2. Largest of 3
 Your Choice: 1

 Enter number: 67

 Number is Odd.

 MENU:

 1. Even/Odd
 2. Largest of 3
 Your Choice: 2

 Enter First number: 67

 Enter Second number: 300

 Enter Third number: 45

 300 is greatest.





WAP to find sum and reverse of entered number's digits.


SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<stdio.h>
#include<conio.h>
 
int main()
{
int i,digit,rev=0,sum=0, num;
 
printf("\n Enter the number: ");
scanf("%d",&num);
 
int n=num;
 
do
{
digit=num%10;
 
sum+=digit;
rev=rev*10+digit;
 
num/=10;
}
while(num>0);
 
printf("\n Reverse: %d",rev);
printf("\n Sum: %d", sum);
 
getch();
return 1;
}
 

INPUT/OUTPUT:

 
 Enter the number: 634

 Reverse: 436
 Sum: 13







1-5 of 5