Hey all, I just received a new project involving me having to generate Japanese poems based on input text given from text files. I just am confused on where to start. The pdf file describing what to do is attached and the replit link is attached below:
https://replit.com/@BrandenS2023/Project-3#project-3-BrandenSecaira/poems.cpp
#Having trouble understanding what I should do with my c++ project, can someone help?
97 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
what are your current thoughts
At the moment, I've read through it and understand it a bit such as what certain numbers in each line of the input should do and the expected output based on said numbers. There's just parts that I really don't get such as the seed, output format and how I run the program with a text file as input
I'll be right back
Ok I'm back
I've taken some time to think, I just don't understand what the seed exactly is in the case of the code
And from what I've seen in the case of the starter code, the only things I really need to change are in the main function
And now I'm having trouble understanding how to make the program make spaces when giving out the output
At the moment, I'm feeling a bit better but still stumped
Yeah, even after some time to think about it, I still feel a bit stumped
What code do you have currently?
Code block would be appreciated
Or is the latest version the poems_v1.cpp on that replit?
What do you mean by "make spaces"? Do you mean std::cout << foo << " " bar << "\n";?
I currently just restarted my code, the one I was using before was not getting me anywhere
Basically, the spaces as in space given after a certain amount of syllables are used, then a space is used to separate them apart
Yes it is that exact version
I apologize for the late reply
I attached a pdf with what I have to do
There's just parts that I really don't get such as the seed
what specifically about the seed would you like explained?
output format
and what about the output format? the PDF seems to give really detailed examples
I should have mentioned I found out about the seed most recently
how I run the program with a text file as input
seems like it's redirected into your program, so your program should read it from stdin
Basically the seed is crucial for the algorithm used to determine which lines are used in the array given and then the syllables used in the array
I just had trouble understanding its use before
I haven't had much sleep lately so I've been pretty slow with comprehending what must be done
if you have any concrete questions with example code, I can try to answer any C/C++ questions you may have
Do you mean newlines?
So what separates my previous sentence from this one?
Aka \n in C and C++?
Or are you just saying that yes you were referring to std::cout << foo << " " bar << "\n";?
I believe I must have been referring to something like this
Cool, yeah lmk if you have any more questions
I guess the question I have now is how I make it so it reads the text file line by line
Either with getline(), or using the "extraction operator" >> to read it directly into variables
I recommend the latter in this case
getline() is more for when you want to read a blob of text and turn it into an array of string
100
3 5 7 5
1 0
For this, how would I use getline() to take out the 100 and put it as an int variable?
I recommend in this case just using int foo; std::cin >> foo; in order to put the value into foo
followed by the same line copy-pasted for every next value, with different variable names
Ok I've got that handled now
It seems to work for the other inputs for the other text files
How would I check the other lines
Like for example checking each number separately on the line with 3 5 7 5 or the line with 1 0
wdym by checking
Asking since I need the first number on the second line to know how many lines the poem must be, and the numbers that come after it should tell how many syllables should be in each line and are also used in the equation to tell what syllable is used
well you just read each number into its own int, whether you have a use for all of them or not
Like taking note of each number separately so it knows the first one is a 3, the other is a 5 and so on
so what is the meaning of the 3, the 5, the 7, and then the 5 in that line
describe it so I know you know
try to think of a short description, cause that can be used for variable names
shorter than this
the 3 is the number of lines in the poem
numbers after the 3 are the number of syllables in each line
yup, exactly
so you read int line_count; (or int lineCount;, depending on whether you're doing it in snake_case or camelCase), and then you use that int to loop that many times
where inside of the loop, you just read an int syllable_count;/int syllableCount;
you can push these syllable counts into a std::vector, but if you don't actually need to for the rest of the program, I wouldn't do that
I keep attempting it but I still am unable to get the other numbers in the other lines
paste the code into a code block
How to Format Code on Discord
Markup
```cpp
int main() {}
```
Result
int main() {}
Note: Back-tick (`) not quotes (')
int foo;
cin >> foo;
int too;
cin >> too; //numbers on other row
int choo;
cin >> choo; // number on last line to indicate if we're using caps
int caps = choo;
cout << caps << endl;
int rows = too;
cout << rows << endl;
int seed = foo;
cout << foo << endl
I'm only getting the numbers in the first and second row
Where it says choo is where it's supposed to get the 3rd row, but instead it's getting another number from the second row
Let's run it:
;compile -Wall -Wextra -Werror -Wpedantic -fsanitize=address,undefined -g
100
3 5 7 5
1 0
#include <iostream>
int main() {
int foo;
std::cin >> foo;
int too;
std::cin >> too; //numbers on other row
int choo;
std::cin >> choo; // number on last line to indicate if we're using caps
int caps = choo;
std::cout << caps << std::endl;
int rows = too;
std::cout << rows << std::endl;
int seed = foo;
std::cout << seed << std::endl;
return EXIT_SUCCESS;
}
Program Output
5
3
100
mynameistrez | 91ms | c++ | x86-64 gcc 13.2 | godbolt.org
Note that I changed the code slightly, as you printed foo at the end, while you probably meant to print seed at the end
what is the reasoning behind assigning stuff manually with = in this code? @fast oar
That's just the way I've been taught to assign variables
try copy-pasting my code block, so you can send it as your own message, cause then you can test stuff with it here to your heart's content. if you edit the message, the bot will automatically rerun your code
yeah but I mean, right here you're reading a number into choo, and then putting a copy of that value in caps. was that intentional?
int choo;
std::cin >> choo; // number on last line to indicate if we're using caps
int caps = choo;
Yes it was
okay, but why?
I wanted to do something similar to what I did with seed where it went from foo to seed in order to be used in the equation
right, but what I mean is that if you're just using choo as a placeholder, just do this instead:
int caps;
std::cin >> caps; // number on last line to indicate if we're using caps
do this, it'll be the best way I can walk you through it
int main() {
int foo;
cin >> foo;
int rows;
cin >> rows; //numbers on other row
int caps;
cin >> caps; //changed
cout << caps << endl;
cout << rows << endl;
int seed = foo;
cout << foo << endl;
int random_num;
// Seed the RNG
rand_int(seed);
for (int i = 0; i < 15; i++) {
random_num = rand_int();
cout << random_num << " ";
}
cout << endl;
return 0;
}
;compile -Wall -Wextra -Werror -Wpedantic -fsanitize=address,undefined -g
100
3 5 7 5
1 0
#include <iostream>
int main() {
int foo;
cin >> foo;
int rows;
cin >> rows; //numbers on other row
int caps;
cin >> caps; //changed
cout << caps << endl;
cout << rows << endl;
int seed = foo;
cout << foo << endl;
int random_num;
// Seed the RNG
rand_int(seed);
for (int i = 0; i < 15; i++) {
random_num = rand_int();
cout << random_num << " ";
}
cout << endl;
return 0;
}
Compiler Output
<source>: In function 'int main()':
<source>:5:1: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
5 | cin >> foo;
| ^~~
| std::cin
In file included from <source>:1:
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/iostream:62:18: note: 'std::cin' declared here
62 | extern istream cin; ///< Linked to standard input
| ^~~
<source>:10:1: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
10 | cout << caps << endl;
| ^~~~
| std::cout
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/iostream:63:18: note: 'std::cout' declared here
63 | extern ostream cout; ///< Linked to standard output
| ^~~~
<source>:10:17: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
10 | cout << caps << endl;
| ^~~~
| std::endl
In file included from /opt/compiler-explorer/gcc-13.2.0/include/
brandensecaira | c++ | x86-64 gcc 13.2 | godbolt.org
good, so now feel free to edit that code, and the bot will automatically rerun it
try to reintroduce the for-loop you sent here
I prefer running it on replit
that's ok, but do consider that others often won't want to take the time to click to a replit link, so it's convenient to view the code right in the conversation
you'll want using namespace std; at the top btw if you don't want to add std:: in front of most lines of your code
I did that in the full code, I'm only showing the main function in this case
yeah, but can you edit it so it compiles, cause the output is valuable too
just copy-paste the entire cpp file you have
It says its too long
ah ok
That's why I wanted to use replit since I don't have nitro to send in the full code
okay, so you first read into an integer called seed
then you read into an integer called line_count, and then you enter a for-loop that loops line_count times, reading one integer every time
and finally you read into a boolean called is_capitalized, and after that into a boolean called is_vertical
Yeah
if you have any specific questions feel free to ask
ok