In: Computer Science
#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
using namespace std;
class SVector
{
public:
int size;
int idx;
char x;
string *sptr;
SVector(char c, int size);// (a)
void insert(string s);
void print();
};
SVector::SVector(char c, int size)
{
x = c;
idx = 0;
this->size = size;
sptr=new string[size];
}
void SVector::insert(string s)
{
//(c)
idx+=1;
sptr[idx]=s;
}
void SVector::print()
{
if(idx != 0)
{
cout << "starting
with " << x << endl;
for(int i = 0; i <
idx; i++)
{
cout << sptr[i] << endl;
}
}
}
int main()
{
SVector *sv[26];
string word;
ifstream fin;
fin.open(".\\data\\fdata.txt");
//cout << fin << endl;
if(!fin)
{
cout << "file not
opened" << endl;
return 0;
}
for(int i = 0; i < 26; i++)
{
char c = 'a' + i;
sv[i] = new
SVector(c,100);//(d);
}
while(true)
{
fin >> word;
if(fin.eof())
break;
int fc =int(word[0]-'a')
//(e);
sv[fc]->insert(word);
}
for(int i = 0; i < 26; i++)
{
sv[i]->print();
}
return 0;
}