#Having trouble understanding what I should do with my c++ project, can someone help?

97 messages · Page 1 of 1 (latest)

fast oar
#

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

BrandenS2023

Run C++ code live in your browser. Write and run code in 50+ languages online with Replit, a powerful IDE, compiler, & interpreter.

junior frigateBOT
#

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.

sweet heath
fast oar
#

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

fast oar
#

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

fast oar
fast oar
#

Yeah, even after some time to think about it, I still feel a bit stumped

quartz kraken
#

Code block would be appreciated

#

Or is the latest version the poems_v1.cpp on that replit?

quartz kraken
fast oar
fast oar
fast oar
#

I apologize for the late reply

#

I attached a pdf with what I have to do

quartz kraken
#

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

fast oar
#

I should have mentioned I found out about the seed most recently

quartz kraken
#

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

fast oar
#

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

quartz kraken
#

if you have any concrete questions with example code, I can try to answer any C/C++ questions you may have

quartz kraken
#

Aka \n in C and C++?

#

Or are you just saying that yes you were referring to std::cout << foo << " " bar << "\n";?

fast oar
quartz kraken
#

Cool, yeah lmk if you have any more questions

fast oar
#

I guess the question I have now is how I make it so it reads the text file line by line

quartz kraken
#

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

fast oar
#

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?

quartz kraken
#

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

fast oar
#

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

quartz kraken
#

wdym by checking

fast oar
#

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

quartz kraken
#

well you just read each number into its own int, whether you have a use for all of them or not

fast oar
#

Like taking note of each number separately so it knows the first one is a 3, the other is a 5 and so on

quartz kraken
#

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

fast oar
#

the 3 is the number of lines in the poem

#

numbers after the 3 are the number of syllables in each line

quartz kraken
#

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

fast oar
#

I keep attempting it but I still am unable to get the other numbers in the other lines

quartz kraken
#

paste the code into a code block

junior frigateBOT
#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
fast oar
#
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

quartz kraken
#

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;
}
sweet cliffBOT
#
Program Output
5
3
100
quartz kraken
#

what is the reasoning behind assigning stuff manually with = in this code? @fast oar

fast oar
#

That's just the way I've been taught to assign variables

quartz kraken
#

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

quartz kraken
fast oar
#

Yes it was

quartz kraken
#

okay, but why?

fast oar
#

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

quartz kraken
#

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
quartz kraken
fast oar
#
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;
}
quartz kraken
#

do this on my code and paste it

#

it'll give a pretty different result

fast oar
#

;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;
}
sweet cliffBOT
#
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/
quartz kraken
#

good, so now feel free to edit that code, and the bot will automatically rerun it

quartz kraken
fast oar
#

I prefer running it on replit

quartz kraken
#

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

fast oar
#

I did that in the full code, I'm only showing the main function in this case

quartz kraken
#

yeah, but can you edit it so it compiles, cause the output is valuable too

#

just copy-paste the entire cpp file you have

fast oar
#

It says its too long

quartz kraken
#

ah ok

fast oar
#

That's why I wanted to use replit since I don't have nitro to send in the full code

quartz kraken
#

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

fast oar
#

Yeah

quartz kraken
#

if you have any specific questions feel free to ask

fast oar
#

ok