Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

BACK to

practical

INTRODUCTION

SECTION – A

WELCOME

C++ AND DATA STRUCTURES

Ashwini E

computer science engineer

TEACHER

former lecturer teresian college mysore

https://www.youtube.com/channel/UCpsOGE9XP-vD-flK6sFNzKA

PROGRAM 1:

FACTS

Frequency is number of times an element present in an array

Write a C++ program to find the frequency presence of an element in an array.

10 20 20 20 30 40

frequency 20 is 3

Syntax

RULES

LIST

OF RULES

1

declaration of class:

class class_name

{

data_members ;

members_function;

};

LIST

OF RULES

2

definition of member function

void class_name::member_function_name( )

{

//

}

3

creating object

class_name object_name ;

Write a C++ program to find the frequency presence of an element in an array.

Program

Class

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

class Frequency

{

private: int a[10], n, ele, count;

public: void readdata( );

void findfreq( );

void display( );

};

Read

void Frequency::readdata( )

{

cout<<"Enter the size of the array:"<<endl;

cin>>n;

cout<<"Enter the array elements:"<<endl;

for(int i=0; i<n; i++)

cin>>a[i];

cout<<"Enter the element to find the frequency"<<endl;

cin>>ele;

}

logical part

Logic

void Frequency::findfreq( )

{

count=0;

for(int i=0; i<n; i++)

if(ele == a[i])

count++;

}

Display

Display Data

void Frequency::display( )

{

if(count > 0)

cout<<ele<<"Occurs"<<count<<" Time"; else cout<<ele<<" Does Not Exists";

}

Main function

Main

void main( )

{

Frequency f;

clrscr( );

f.readdata( );

f.findfreq( );

f.display( );

getch( );

}

full_program

void Frequency::display( )

{

if(count > 0)

cout<<ele<<" Occurs"<<count<<" Time"; else

cout<<ele<<" Does Not Exists";

}

void main( ) //Main function

{

Frequency f;

clrscr( );

f.readdata( );

f.findfreq( );

f.display( );

getch( );

}

#include<iostream.h>

#include<conio.h>

class Frequency

{

private: int a[10], n, ele, count;

public: void readdata( );

void findfreq( );

void display( );

};

void Frequency::readdata( )

{

cout<<"Enter the size of the array:"<<endl;

cin>>n;

cout<<"Enter the array elements:"<<endl;

for(int i=0; i<n; i++)

cin>>a[i];

cout<<"Enter the element to find the frequency"<<endl

; cin>>ele;

}

void Frequency::findfreq( ) /

{

count=0;

for(int i=0; i<n; i++)

if(ele == a[i])

count++;

}

output :

Output

Learn more about creating dynamic, engaging presentations with Prezi