Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
C++
#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:

C++
#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;

}
Posted
Updated 16-Jan-22 7:55am
v3
Comments
Richard MacCutchan 15-Jan-22 10:56am    
"Is anyone here able to do this task?"
Yes, many people. But it is your assignment so you are expected to do the work. If you have specific problems with the code that you write, then post the details and people will try to help you.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

And while I'm here ...
1) Don't double space your code - it doesn't make it look "bigger" or "better", it just makes it harder to read as less fits on thE screen at once.
2) Indent your code: it makes it a lot more readable as you can see more eaily what is a part of what, where functions begin and end, and so forth.
3) Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know.
 
Share this answer
 
Comments
Most Palone 15-Jan-22 11:55am    
Thanks for your advice. You are right about what you said. I don't want you to do the work, I just need to know how to do the next step. which is making character arrays for each word in the paragraph file. Then I have to make pointers for all arrays made and then I have to loop and ifstream the translation file to match and replace the english words translated with their translations.

I just need to know how to make char array for each word in the paragraph file and make pointers for those arrays. If you can help me with this, it would be appreciated. Thanks.
OriginalGriff 15-Jan-22 12:00pm    
char *words[numberOfWords];
Then set each pointer to the word.
What's the problem?
Learn coding with some Learn C tutorial and think about some solution.

some tips:
- you can store your translation strings in an array of structs like
C++
struct Translation {
 char *english;
 char *urdu;
};

- alloc and free all memory of the strings (with additional terminating zero at end)
- to translate you should use shouldnt use strtok, but access every char of the string to find "." or ",".
- build a result string and dont manipulate the input (also easier for debugging)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900