C++ PROGRAM:
#define MAIN 1
#include <bits/stdc++.h>
using namespace std;
class splitstring : public string {
vector<string> flds;
public:
splitstring(char *s) : string(s) { };
vector<string>& split(char delim, int rep=0);
};
// split: receives a char delimiter; returns a vector of strings
// By default ignores repeated delimiters, unless argument rep == 1.
vector<string>& splitstring::split(char delim, int rep) {
if (!flds.empty()) flds.clear(); // empty vector if necessary
string work = data();
string buf = “”;
int i = 0;
while (i < work.length()) {
if (work[i] != delim)
buf += work[i];
else if (rep == 1) {
flds.push_back(buf);
buf = “”;
} else if (buf.length() > 0) {
flds.push_back(buf);
buf = “”;
}
i++;
}
if (!buf.empty())
flds.push_back(buf);
return flds;
}
main()
{
cout<<“Enter student information in the format name*ID*GPA : “<<endl;
string str;
cin>>str;
int n=str.size();
char a[n+1] ;
strcpy(a, str.c_str()); //converting string to char[]
char *utk=a; //converting char[] to char*
splitstring s(utk); // input string is passed to the function splitstring
cout<<endl;
vector<string> fields = s.split(‘*’); //split function is called to split the string
//after every *.
for (int k = 0; k < fields.size(); k++){
if(k==0)
cout <<“Name : ” << fields[k] << endl;
else if(k==1)
cout <<“ID : ” << fields[k] << endl;
else
cout <<“GPA : ” << fields[k] << endl;
}
}
CODE SCREENSHOTS:
![1 #define MAINI 3 #include <bits/stdc++ . h> 4 using namespace std; 6 class splitstring public string t vector<string> flds; 8 public: splitstring(char *s)string(s) t ; vector<string>& split(char delim, int rep-0); 10 12 13 // split: receives a char delimiter; returns a vector of strings 14 // By default ignores repeated delimiters, unless argument repー1 15 vector<string>& splitstring::split(char delim, int rep) 16 17 18 19 20 21 if (!flds.empty)) flds.clear(); // empty vector if necessary string work data(); string buf = ; (i < work. length()) delim) while { if (work[i] ! buf work[i]; 23 24 25 26 27 28 29 30 31 32 else if (rep1) { flds.push_back (buf); buf- else if (buf.length() >0) flds.push_back (buf); buf if (!buf.empty)) flds.push_back (buf); 34 35 return flds](https://media.cheggcdn.com/media%2Fefe%2Fefe1bd59-4d84-4cdd-839b-b29cf3764f0e%2Fphp0lXHTO.png)

OUTPUT SCREENSHOT:
