I'm a beginner programmer who got this assignment in C++. Is anyone here able to do this task? I have done the input of file and paragraph word count(code shown below). But I don't know how to do this further. It would be highly appreciated if anyone helps.
Here's the task:
You have a list of English words along with meanings in Urdu (but also typed in English e.g. “Butterfly” – “Tittli”, “Beautiful” – “Khubsurat” etc..). You are required to take paragraph(s) as input from user (must be read from file) and replace available English words with Urdu words. Store the final paragraph in an output file.
- You must have atleast 50 words with English and Urdu translation stored in file. (DONE)
- No use of string, use char array.
- These words must be stored into a file which is editable anytime without changing the actual solution code. (DONE)
- The upper/lower representation of first character of each word must also be taken care of while replacing.
- Display the output on console as well as save the output in a separate file.
- Also print all the words which are replaced in paragraph(s) with total.
Sample Input:
It was Friday and sunny day. I went to a garden. The air was so cool and fresh there. I felt very good after walking for 10 minutes. There were very beautiful flowers there as well. I saw a butterfly on one flower with yellow color. I decided to visit the place often after this beautiful experience.
Sample Output:
It was Jumma and sunny din. I went to a bagh. The hawa was so thanda and taza there. I felt very acha after chalna for 10 minutes. There were very khusurat phool there as well. I dekha a tittli on aik phool with peela rang. I decided to visit the jagah often after this khubsurat experience.
Dictionary Words Used : 16
Friday - Jumma
Day - Din
Garden - Bagh
Air - Hawa
Cool - Thanda
Fresh - Taza
Good - Acha
Walking - Chalna
Beautiful - Khubsurat
Flower - Phool
Saw - Dekha
Butterfly - Tittli
One - Aik
Yellow - Peela
Color - Rang
Place - Jagah
Submission Details:
· You need to submit the Source Code.cpp files with Input, Dictionary & Output. txt files zipped file.
Due Date: 16th December 2022 (Sunday: 11:59pm).
Here's the code I have written so far:
#include<iostream>
#include<fstream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
int count = 0;
int i;
ifstream paragraphfile("paragraphfile.txt", ios::in);
if (!paragraphfile)
{
cout << "File does not exist." << endl;
exit(0);
}
char wholepara[99999] = "";
while (!paragraphfile.eof())
{
char para[9999] = "";
paragraphfile.getline(para, 9999);
strcat_s(wholepara, para);
}
cout << wholepara << endl << endl;
{
char separators[] = " ,\t\n.";
char* token;
char* next_token;
token = strtok_s(wholepara, separators, &next_token);
while ((token != NULL))
{
if (token != NULL)
{
count++;
cout << "\n" << token << endl;
token = strtok_s(NULL, separators, &next_token);
}
cout << "Total words in the paragraph: " << count << endl;
}
}
return 0;
}
please email me at [DELETED]@gmail.com or comment below if you can help. Thanks.
What I have tried:
#include<iostream>
#include<fstream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
int count = 0;
int i;
ifstream paragraphfile("paragraphfile.txt", ios::in);
if (!paragraphfile)
{
cout << "File does not exist." << endl;
exit(0);
}
char wholepara[99999] = "";
while (!paragraphfile.eof())
{
char para[9999] = "";
paragraphfile.getline(para, 9999);
strcat_s(wholepara, para);
}
cout << wholepara << endl << endl;
{
char separators[] = " ,\t\n.";
char* token;
char* next_token;
token = strtok_s(wholepara, separators, &next_token);
while ((token != NULL))
{
if (token != NULL)
{
count++;
cout << "\n" << token << endl;
token = strtok_s(NULL, separators, &next_token);
}
cout << "Total words in the paragraph: " << count << endl;
}
}
return 0;
}