Beginners program - college

#include<iostream>
#include<iomanip>
#include<conio.h>
class flag
{
int n, freq, i, a[10], ele;
public:
void read();
void find();
void display();
};
void flag :: read()
{
cout<<"Enter the size of an array ";
cin>>n;
cout<<endl<<"Enter the element into an array ";
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element to be searched ";
cin>>ele;
}
void flag :: find()
{
freq=0;
for(i=0; i<n; i++)
{
if(a[i] == ele)
{
freq++;
}
}
}
void flag :: display()
{
if(freq>0)
cout<<endl<<ele<<" is found and "<<freq<<" frequeny";
else
cout<<ele<<" is not found";
}

void main()
{
clrscr();
flag F;
F.read();
F.find();
F.display();
getch();
}

Getting this error: 'cout' was not declared in this scope

how to fix this error?


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>
#include<iomanip>

using namespace std;

class flag
{
    int n, freq, i, a[10], ele;
public:
    void read();
    void find();
    void display();
};
void flag :: read()
{
    cout<<"Enter the size of an array ";
    cin>>n;
    cout<<endl<<"Enter the element into an array ";
    for(i=0; i<n; i++)
        cin>>a[i];
    cout<<"Enter the element to be searched ";
    cin>>ele;
}
void flag :: find()
{
    freq=0;
    for(i=0; i<n; i++)
    {
        if(a[i] == ele)
        {
            freq++;
        }
    }
}
void flag :: display()
{
    if(freq>0)
        cout<<endl<<ele<<" is found and "<<freq<<" frequeny";
    else
        cout<<ele<<" is not found";
}

int main()
{
    flag F;
    F.read();
    F.find();
    F.display();
}
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
50
51
#include <iostream>
#include <algorithm>

constexpr size_t MaxArr {10};

class flag {
	int ele {}, a[MaxArr] {};
	size_t n {}, freq {};

public:
	void read();
	void find();
	void display();
};

void flag::read() {
	std::cout << "Enter the size of array (max of " << MaxArr << "): ";
	std::cin >> n;

	n = std::min(n, MaxArr);

	std::cout << "\nEnter the elements into array ";

	for (size_t i = 0; i < n; ++i)
		std::cin >> a[i];
}

void flag::find() {
	std::cout << "Enter the element to be searched ";
	std::cin >> ele;

	freq = 0;

	for (size_t i = 0; i < n; ++i)
		freq += a[i] == ele;
}

void flag::display() {
	if (freq > 0)
		std::cout << '\n' << ele << " is found and " << freq << " frequency\n";
	else
		std::cout << '\n' << ele << " is not found\n";
}

int main() {
	flag F;

	F.read();
	F.find();
	F.display();
}

Topic archived. No new replies allowed.