0% found this document useful (0 votes)
13 views

C++ programs

Cs

Uploaded by

jyotsnashree2021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
13 views

C++ programs

Cs

Uploaded by

jyotsnashree2021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 28
CH Programming 3 S C++ Programming ‘Write a program to find the frequency of presence of an elelment in an array. Logic: ‘Counting the given element(EELE) for how many times it exists in an array by traversing. Initially compare ELE with first clement in an array. If first element is equal to ELE, increment the count by 1. Next compare ELE with second element, if second clementis equal to ELE, again increment the count by 1. Similarly compare ELE with all other elements until the last.clement. Whenever comparison gives true result, increment the.countiby 1. Finally display the count. Example: Finding the frequency of 25 from the following array: ~ |e [|e fs | 9 | Af) AQ] A) AB) Ala When ELE=All], Initially Count=0 ; 1=0, 25=25, (Tue) Count=Count+ 1. ‘Cout=0+1=1 1=1, 25=16, (False) No increment Count= 1 J=2, 25=67, (False) No increment ‘Count = 1 J=3, 25=25, (True) Count= Count +1. Count = 1+1=2 1=4, 25=19, (False) No increment ‘Count = 2 1=5 (Outofrange). Therefore frequency of 25 =? Program: #include #include #include class Frequency { private: int n, a[100], i, ELE, freq; public: void input() ; void findfrequency() void display() ;C++ Programming void Frequency :: input( ) { cin >> nter the array elements” > ali] ; cout > ELE ; void Frequency :: findfrequency( ) { freq for(i=0; i 0) ; cout #include #include ah tnclude & std -h>class Insert f private: int n, af 100], i, BI public: void input() ; void insertion( ) void display( ) ;. IE, pos. 5 Le void Insert :: input() { cout >n; cout > ali} ; cout > ELE ; cout > pos ;. } : void Insert :: insertion( ) { if(pos > n) { cout =pos; i-) afi+ 1] = ali] s a[pos] = ELE ; n=nt1;C+ Programming } } void Insert :: display() { cout #include BinclndeSiomaniDI 5 aprncbuucte { private: int n, a[100], i, ELE, pos ; public: void input() ; void deletion( ) ; void display() ; Bs void Delete :: input() t cout >n; cout > afi] 5 cout > pos 5} void Delete :: deletion( ) { if(pos > n-1) { cout #include #include class Sort { private: int n, a[100] ; public: void input) ;CH Programming 7 void sorting( ) ; void display( ) ; hs void Sort :: input( ) { cout >n; cout > ai] ; } void Sort :: sorting( ) { int t, j,i; for(i=1; i= 1) { ~if(alj] #include class Search { private: int a[100], n, ELE, loc, i; public: void input() ; void bin_search( ) ; void display() ; hs void Search :: input() { cout >n; cout > afi] ; cout > ELE ; } void Search :: bin_search( ) { int beg = 0, end=n-1, mid; loc =-1; while(beg = 0) cout #include #include class Interest { private: double P, T, R, SI; public: void input( ) ; void compute( ) ; void display( ) ; 33 void Interest :: input() { cout >P>>T>>R; } void Interest :: compute( ) { SI=(P*T*R)/100;, Void Interest :: display( ) { cout 0, print the real and distinct roots. 3) If the discriminant 0, roots are real and distinct, x=CH Programming 7 D #include #include Htaclude 2 ardkele “h> class Quadratic { private: double a, b, c, rl, 12, d; public: void getdata( ) ; void compute( ) ; void display( ) ; 35 void Quadratic :: getdata() { cout >a>>b>>c; } void Quadratic :: compute( ) { d=b*b-4*a*c; if(d = 0) { cout 0) { cout #include Hinclude class FindCube { public: inline int CUBE(int x) { retumn(x * x * x); } 33 void main( ) { FindCube F ; i intns CL SEED) ‘ cout > n; cout #include class Student { private: int regno ; char name[20] ; public: void base_getdata( ) { cout > regno ; } void base_display( ) { cout > markl >> mark2 ; total = mark1 + mark2 ; } void derived_display( ) ‘ 5 cout #include class Student { private: int regno ; char name[20] ; float fee ; public: void getdata( ) ; void display( ) ; bs void Student :: getdata() : cout > regno ; cout > name ; cout > fee;C+ Programming 21 void Student :: display( ) { cout getdata() ; ptr > display() ; getch() ; } Output: Enter the register number : 20146789 Enter the student name : Soujanya Enter the student fees : 5000.00 The student details are... Register number = $20146789 Name = Soujanya Fees = 5000.00

You might also like