If sourcefile.txt contains the following data
a 2 ab 10 2 ab 10 2 2 10 8
then the graph in graph.txt file would be
*
* *
* * *
* * * * *
a 2 ab 10 8
#include<iostream>
#include<fstream>
using namespace std;
class Graphview
{public:
int big;
int biggest(int num[],int numofelements);
void showfreqgraph(string store[],int storefreq[],int numofelements,ofstream &output);
void computefrequency(ifstream &input,string store[],int storefreq[],int &numofelements);
};
int main()
{ ifstream input("sourcefile.txt");
ofstream output("graph.txt");
string store[100];int storefreq[100];
int numofelements=0;
Graphview one;
one.computefrequency(input,store,storefreq,numofelements);
one.showfreqgraph(store,storefreq,numofelements,output);
return 0;
}
int Graphview::biggest(int num[],int numofelements)
{ int big=0;
for(int i=0;i<numofelements;i++)
{
if(num[i]>big)
big=num[i];
}
return big;
}
void Graphview:: showfreqgraph(string store[],int storefreq[],int numofelements,ofstream &output)
{ for(int k=0;k<numofelements;k++)
cout<<store[k]<<"\t----> "<<storefreq[k]<<endl;
cout<<endl<<endl;
int i;
big=biggest(storefreq,numofelements);
int freqprintstart[big];
for(i=0;i<numofelements;i++)
freqprintstart[i]=big-storefreq[i];
for(int line=0;line<big;line++)
{
for(int k=0;k<numofelements;k++)
{
if(line>=freqprintstart[k])
{cout<<"*\t";
output<<"*\t";
}
else
{cout<<"\t";
output<<"\t";
}
}
cout<<endl;
output<<endl;
}
for(i=0;i<numofelements;i++)
{ cout<<store[i]<<"\t";
output<<store[i]<<"\t";
}
}
void Graphview::computefrequency(ifstream &input,string store[],int storefreq[],int &numofelements)
{ int i,j,k,c;
string x[50];
for(i=0;!input.eof();i++)
input>>x[i];
cout<<"number of elements from file:" <<i-1<<endl;
for(j=0;j<i;j++)
{c=1;int remember;
for(k=j+1;k<i;k++)
{ if(x[j]==x[k])
{c++;i--;remember=k;
while(remember<i)
{ x[remember]=x[remember+1];
remember++;
}
k--;
}
}
store[j]=x[j];
storefreq[j]=c;
}
numofelements=j-1;
}
a 2 ab 10 2 ab 10 2 2 10 8
then the graph in graph.txt file would be
*
* *
* * *
* * * * *
a 2 ab 10 8
#include<iostream>
#include<fstream>
using namespace std;
class Graphview
{public:
int big;
int biggest(int num[],int numofelements);
void showfreqgraph(string store[],int storefreq[],int numofelements,ofstream &output);
void computefrequency(ifstream &input,string store[],int storefreq[],int &numofelements);
};
int main()
{ ifstream input("sourcefile.txt");
ofstream output("graph.txt");
string store[100];int storefreq[100];
int numofelements=0;
Graphview one;
one.computefrequency(input,store,storefreq,numofelements);
one.showfreqgraph(store,storefreq,numofelements,output);
return 0;
}
int Graphview::biggest(int num[],int numofelements)
{ int big=0;
for(int i=0;i<numofelements;i++)
{
if(num[i]>big)
big=num[i];
}
return big;
}
void Graphview:: showfreqgraph(string store[],int storefreq[],int numofelements,ofstream &output)
{ for(int k=0;k<numofelements;k++)
cout<<store[k]<<"\t----> "<<storefreq[k]<<endl;
cout<<endl<<endl;
int i;
big=biggest(storefreq,numofelements);
int freqprintstart[big];
for(i=0;i<numofelements;i++)
freqprintstart[i]=big-storefreq[i];
for(int line=0;line<big;line++)
{
for(int k=0;k<numofelements;k++)
{
if(line>=freqprintstart[k])
{cout<<"*\t";
output<<"*\t";
}
else
{cout<<"\t";
output<<"\t";
}
}
cout<<endl;
output<<endl;
}
for(i=0;i<numofelements;i++)
{ cout<<store[i]<<"\t";
output<<store[i]<<"\t";
}
}
void Graphview::computefrequency(ifstream &input,string store[],int storefreq[],int &numofelements)
{ int i,j,k,c;
string x[50];
for(i=0;!input.eof();i++)
input>>x[i];
cout<<"number of elements from file:" <<i-1<<endl;
for(j=0;j<i;j++)
{c=1;int remember;
for(k=j+1;k<i;k++)
{ if(x[j]==x[k])
{c++;i--;remember=k;
while(remember<i)
{ x[remember]=x[remember+1];
remember++;
}
k--;
}
}
store[j]=x[j];
storefreq[j]=c;
}
numofelements=j-1;
}
No comments:
Post a Comment