हिंदी माध्यम नोट्स
write a program to develop string class function using member function , square and cube function
write a program to develop string class function using member function .
Explanation
सबसे पहले class string को declare किया जाता है | इस class मे एक variable length , first , last और full_name को declare किया जाता है | इसका access mode private होता है अतः इसे class string मे ही use किया जा ससकता है | class string मे तीन function के header को declare किया जाता है |
len() : इसका access mode public है | इसमें string के length को find किया जाता है | इस function से return हुई value को private mode length मे assign किया जाता है |
compare() : इसमें compare operation को perform किया जाता है |
concentrate () : इसमें दो string को merge किया जाता है |
इसके बाद scope resolution operator से class स्क्क्सोपे के बहार इन सभी function को define किया जाता है |
string :: length () मे ,
सबसे पहले function मे यूजर द्वारा input की गयी string first को pass किया जाता है | length को find करने के लिए loop को चलाया जाता है |
loop मे control variable ‘i’ को ‘0’ से initial किया जाता है | ये loop तब तक चलाया जाता है जब तक string की value null pointer नहीं होती है |
loop की body मे , length के value को update किया जाता है | इसके बाद control variable की value को भी update किया जाता है |
loop के execute होने के बाद length की value को return किया जाता है |
string :: concatenate() मे ,
इस function मे दो string first और last को pass किया जाता है |
concatenate operation के लिए loop चलाया जाता है |
loop मे ‘i’ की value को length + 1 से initial होती है | और ये loop तब तक चलाया जाता है जब तक last मे null pointer नहीं आ जाता है | इस loop मे दूसरा control variable j भी होता है | जिसका initial ‘0’ से किया जाता है |
loop की body मे first [i]=last[j]; statement perform होता है |
loop के बाद first को return किया जाता है |
इस function मे दो string first और second को pass किया जाता है |
compare operation के लिए loop चलाया जाता है |
loop मे ‘i’ की value को ‘0’ से initial होती है | और ये loop तब तक चलाया जाता है जब तक first और second मे null pointer नहीं आ जाता है | इस loop मे i की value को update किया जाता है |
loop की body मे first और second से compare किया जाता है |
अगर first और second के element match होता है जब f की value ‘1’ रहती है अन्यथा
f की value ‘0’ हो जाती है और loop terminate हो जाता है |
loop के बहार f की value को return किया जाता है |
#include<iostream.h>
#include<conio.h>
class string {
private :
int length ;
string first ;
string last ;
string full_name;
public:
int length (char first [] )
void concatenate(string first , string last )
void compare (string 1 , string 2 )
}
string :: length (first)
{
{
int i ;
for(i=0;first[i]!=”\0″;i++)
{
length ++;
}
}
string :: concatenate(string first , string last)
{
int len;
len=length(first);
for(i=length+1 ,j=0;last[j]==’\0′;i++,j++)
{
first[i]=last[j];
}
cout<<“Full name :”<<first;
}
string :: void compare (first , second )
{
int f ;
int i ;
for(i=0 ,j=0;first[i]==’\0′ && first[i]==’\0′;i++)
{
if(first[i]== last [i])
{
f =1 ;
}
else{
f ==0;
}
}
return f ;
}
}
void main()
{
string c;
char first [60],last_name[60];
cout<<“Enter first name :”<<endl;
std.cin(first_name,60);
cout<<“Enter last name :”<<endl;
std.cin(last_name,60);
c.concatenate(first ,last_name);
int l= c.length (first_name);
cout<<“Length :”<<l;
int count = c.compare (first ,last_name);
if(count == 1)
{
cout <<“both string are same “<<endl;
}
else
{
cout<<“both string are not same “<<endl;
}
getch();
}
उदाहरन 2 :
write a program to square and cube function using member function.
सबसे पहले class operation को declare किया जाता है | जिसमे class के लिए variable और member function के prototype को ही delclare किया जाता है |
square () से sqaure operation perform होता है | इसे square (int a) से declare किया जाता है जिसमे a class operation का private variable है |
cube () से cube perform होता है इसे cube (int a) से declare किया जाता है जिसमे a class operation का private variable है |
class scope को close करने के बाद scope resolution से इन सभी function की definition को define किया जाता है |
इसके लिए निन्म syntax होता है :
operation :: square (int a ) {
function _ body ;
}
operation :: cube (int a ) {
function _ body ;
}
main() मे ,
सबसे पहले यूजर से एक value को input किया जाता है | इसके बाद class operation के object को define किया जाता है इस object से class के सभी function को define किया जाता है |
source code
#inclue<iostrem>
#include<conio>
using namespace std;
class operation
{
private :
int a;
private :
void square (int a );
void cube (int a );
void display( int a , int b )
{
cout<<“square value is “<<square (int a )<<endl;
cout<<“cube value is “<<cube (int a )<<endl;
} ; // close of class
peration :: sqaure (int a ) {
return a*a;
}
operation :: cube (int a) {
return a*a*a ;
}
}
void main()
{
int num1 ;
cout<<“enter number :”<<endl;
cin>>num1 ;
intca.display(num1) ;
getch();
}
इसका आउटपुट होगा :
enter number :12
square value is 144
cube value is 1728
Recent Posts
Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic
Question Tag Definition • A question tag is a small question at the end of a…
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
Report Writing examples in english grammer How to Write Reports explain Exercise
Report Writing • How to Write Reports • Just as no definite rules can be laid down…
Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th
Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…