Thursday, February 28, 2013

OOCP (CPP) : Example # 13 : CPP Single Inheritance

OOCP (CPP)  :  Example #  13 : CPP Single Inheritance 

* Lets start learning about cpp inheritance.
* Following example is simple inheritance : Single Inheritance consist of one base class and one derived class.


//Written by Latest Technology Guide    
//Title : OOCP (CPP)  :  Example #  
13 : CPP Single Inheritance 

// Inheritance 01 - Simple Derived class as private from Base class
// Single Inheritance

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

class B
{
private:
int a;
public:
int b;
void get_ab();
int get_a();
void show_a();
void line()
{
cout << "Base class Line function called..." << endl;
}
};

class D : private B
{
private:
int c;
public:
void mul();
void display();
void line()
{
cout << "Derived class line function called..." << endl;
}

};

void B :: get_ab()
{
cout << "Enter the value of A and B " << endl;
cin >> a >> b;
}

int B :: get_a()
{
return a;
}

void B :: show_a()
{
cout << "Base class called..." << endl;
cout << " A ==> " << a << endl;
}
void D :: mul()
{
get_ab();
c = b * get_a();
}
void D :: display()
{
cout << "Derived class called " << endl;
show_a();
cout << " B ==> " << b << endl;
cout << " C ==> " << c << endl;
}

//=================================================
// Void Main
//=================================================
void main()
{
clrscr();
D D1; //derived class object

D1.mul();
D1.display();

cout << endl;

D1.mul();
D1.display();
D1.line();

getch();
}


Output:
* You will find output as you have entered value.

--------------------------------------------------------------------------------
OOCP (CPP)  :  Example #  13 : CPP Single Inheritance 

* Example demonstrate how to create your first inheritance program using cpp.
* in example B stands for Base Class while D stands for Derived class.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

C Language Example # 28 Array Example : Create and Display value from Array


C Language Example # 28 Array Example : Create and Display value from Array.

* Program will create array and will display value from it.

//Written by Latest Technology Guide    
//Title : C Language Example # 28 Array Example : Create and Display value from Array.



#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int a[5]={0},i;

printf("\t\t\t : Array Value is :");
for(i=0;i<5;i++)
printf("\na[%d] = %d",i,a[i]);

printf("\n\n\t\t\t : Now Enter Value for Array A : \n");

for(i=0;i<5;i++)
{
printf("a[%d]",i);
scanf("%d",&a[i]);
}

printf("\n\n\t\t\t : Now See New Value of Array A : ");

for(i=0;i<5;i++)
printf("\na[%d] = %d",i,a[i]);

getch();
}


Output:

* Program will display value from array.

--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 28 Array Example : Create and Display value from Array.


* Program will create static array.
* Program will fetch value from user and will store into array..
* Program will display value from array.

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

Wednesday, February 27, 2013

OOCP (CPP) : Example # 12 : CPP Operator New and Delete

OOCP (CPP)  :  Example #  12 : CPP Operator New and Delete.

* Lets allocate memory run time.
* new operator example using cpp language.

* delete operator example using cpp language.
//Written by Latest Technology Guide    
//Title : OOCP (CPP)  :  Example # 
 12 : CPP Operator New and Delete.


#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>

class String
{
private:
char *name;
int length;
public:
String(char *s)
{
length=strlen(s);
name = new char[length+1];
strcpy(name,s);
}
String()
{
length=0;
name = new char[length+1];
}
void display()
{
cout << "Name : " << name << endl;
}
void join(String &a, String &b);
};

//=================================================
// Join Member Function of String
//=================================================
void String :: join(String &a, String &b)
{
length = a.length + b.length;
delete name;

name = new char[length+1];
strcpy(name,a.name);
strcat(name,b.name);
}

//=================================================
// Main Function
//=================================================
void main()
{
clrscr();
String n1("MCA "),n2(" GTU "),n3("India"),s1,s2;

//main purpose of join
s1.join(n1,n2);
s2.join(s1,n3);

n1.display();
n2.display();
n3.display();
s1.display();
s2.display();

getch();
}

Output:
* You will find output as combination of string1 and string2.

--------------------------------------------------------------------------------
OOCP (CPP)  :  Example #  12 : CPP Operator New and Delete.

* Example demonstrate how to allocate memory on the go (Runtime memory allocation using cpp).
* Program demonstrate use of new operator in cpp.

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

C Language Example # 27 Example : Count upper, lower and other characters

C Language Example # 27 Example : Count upper, lower and other characters.

* Program will count total number of upper letter, lower letter and other characters..

//Written by Latest Technology Guide    
//Title : C Language Example # 27 Example : Count upper, lower and other characters.

#include <stdio.h>
#include <conio.h>
#include <ctype.h>
void main()
{
clrscr();

int i=0,upper=0,lower=0,other=0;
char str[50];

printf("Enter String : ");
gets(str);

do{
if(isupper(str[i]))
upper++;
else if(islower(str[i]))
lower++;
else
other++;
}while(str[++i]!=NULL);

printf("\n\t\t\t : Character Summary is : \n");

printf("\n\t Upper Characters are : %d",upper);
printf("\n\t Lower Characters are : %d",lower);
printf("\n\t Other Characters are : %d",other);
printf("\n\t --------------------------");
printf("\n\t Total Characters are : %d",upper+lower+other);

getch();
}


Output:

* Program will display total number of upper letter.

* Program will display total number of lower letter.
* Program will display total number of other characters.

--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 27 Example : Count upper, lower and other characters.

* Program will check one by one character and will compare with upper, lower and other character.
* After counting it will display upper letter, lower letter and other characters.

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

Tuesday, February 26, 2013

C Language Example # 26 Example : Find and Replace Character

C Language Example # 26 Example : Find and Replace Character.

* Find character and replace.

//Written by Latest Technology Guide    
//Title : C Language Example # 26 Example : Find and Replace Character.

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
void main()
{
clrscr();
int i,n,j=0;
char str[70],addstr[50],find[2],replace[2];

printf("Enter the String :");
gets(str);

printf("Enter Character to Find : ");
scanf("%c",&find);

printf("Enter Character to Replace : ");
scanf("%c",&replace);

for(i=0;i<strlen(str);i++)
{
if(str[i]==find[0])
str[i]=replace[0];
}

puts(str);

getch();
}


Output:

* Enter String.

* Enter character to find
* Enter character to replace.

--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 26 Example : Find and Replace Character.
* Program will find character and replace with new character.

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

Monday, February 25, 2013

C Language Example # 25 Example : Join two string without function


C Language Example # 25 Example : Concatenate the String at String 1 with the use of Logic.

* Concatenate two string without function..
* Combine two string without function.
* Join two string without function.

//Written by Latest Technology Guide    
//Title : C Language Example # 25 Example : Concatenate the String at Str 1 with the use of Logic.


#include <stdio.h>
#include <conio.h>
# include <string.h>

void main()
{
clrscr();
char str1[20]={"This is My "}, str2[20];
int i=0,j=0;

printf("Enter String 2 :");
gets(str2);

printf("\nConcatenate the String at Str 1 with the use of Logic\n\n");

while(1)
{
if(str1[i]!=NULL)
{
i=i+1;
continue;
}

str1[i]=str2[j];
i=i+1;
j=j+1;

if(str2[j]==NULL)
break;
}
str1[i]=NULL;
printf("String 1 is \n\n");
puts(str1);

printf("\n Concatenate with the use of function strcat()");
strcat(str1,str2);
printf("\n Content of Str 1 :");
puts(str1);

getch();
}

Output:

* Program will join two string without using function.

--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 25 Example : Concatenate the String at String 1 with the use of Logic.

* Enter Your String 1
* Enter Sting 2.
* Program will display concatenate of two string.

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

Microsoft Visual Studio Lesson # 04

Microsoft Visual Studio Lesson # 04

* Lets Move to Next Application, Its about use of Combo Box Tool. 
* ComboBox Tool of Visual Studio is very much useful when you want to give some choice to the user.
* Here we have written simple code 
  * Add new items to the ComboBox, 
  * Remove Selected items from ComboBox
  * Remove All Items from ComboBox
* Exit From Application.


Step 1 : Start Visual Studio 2008 and Create New Windows Application as shown in previous post.

Step 2 : Add 1 Textbox, 1 ComboBox and 4 Button as shown in the following figure.



Step 3 : Now add code in all Button as shown in the following figure.



Step 4 : Save Project and Test it .



If you have any questions, please post comment.

Sunday, February 24, 2013

OOCP (CPP) : Example # 11 : Concatenate two string using class method join in C++



OOCP (CPP)  :  Example #  11 : Concatenate two string using class method join in C++

* Lets start learning CPP (C++) Using Example.
* Constructor Example using c++.

//Written by Latest Technology Guide    
//Title : OOCP (CPP)  :  Example # 
 11 : Concatenate two string using class method join in C++

#include <iostream.h>

#include <iomanip.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>

class String
{
private:
char *st;
int len;
public:
String()
{
cout << endl << "Simple Constructor called..." << endl;
}
String(char *s)
{
cout << endl << "1 Para Constructor called..." << endl;
strcpy(st,s);
len = strlen(st);
}
void join(String a, String b);
void display();
};

void String :: join(String a, String b)
{
strcat(a.st,b.st);
strcat(st,a.st);
len = strlen(st);
}
void String ::  display()
{
cout << "String is : " << st << endl;
cout << "Lengt  is : " << len << endl;
}


//=================================================
// Void Main
//=================================================

void main()
{
String S1("Abcd "),S2("Xyz "),S3("Pqr ");

cout << "String 1 is : " << endl;
S1.display();
cout << "String 2 is : " << endl;
S2.display();
cout << "String 3 is : " << endl;
S3.display();
cout << "S1.Join(2,3) is : " << endl;

S1.join(S2,S3);
S1.display();
getch();
}


Output:
* You will find output as combination of string1 and string2.

--------------------------------------------------------------------------------
OOCP (CPP)  :  Example #  11 : Concatenate two string using class method join in C++

* Example demonstrate how to concatenate two string using method in c++.
* String class contains two constructor and having two method named join and display.
* Join method of string class can be used to join two string.
* Display method can be used to display value from the private variable.

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

C Language Example # 24 Example : Find string inside a string

C Language Example # 24 Example : Find string inside a string.

* Find character from string.

//Written by Latest Technology Guide    
//Title : C Language Example # 24 Example : Find string inside a string.


#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
clrscr();
char ch[20],find[20],*i;

printf("Enter String 1 : ");
gets(ch);

printf("Enter String to Find :");
gets(find);

if(strstr(ch,find)==NULL)
printf("String Not Found");
else
printf("String Found");

getch();
}

Output:

* Program will display that string is found in main string or not.

--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 24 Example : Find string inside a string

* Enter Your Main String
* Then enter string you want to find from main string.
* Program will display that string is exist or not..

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.