[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
I have a C++ homework assignment and I would REALLY appreciate
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /wsr/ - Worksafe Requests

Thread replies: 15
Thread images: 1
File: eeeeeeeeeeee.png (33 KB, 854x531) Image search: [Google]
eeeeeeeeeeee.png
33 KB, 854x531
I have a C++ homework assignment and I would REALLY appreciate if someone could help me out here.

I am working on a very simple program, which will receive the name of a file and a number (how much you want to delay your subtitles for from that file), then save that file as another file with delayed time. My question here is how to write a function that will change the time.

Let's say that the file looks like that:

1
00:00:49,100 --> 00:00:52,515
- Everything in place?
- You shouldn't have replaced me.

2
00:00:52,770 --> 00:00:55,391
I know, but I wanted to take your shift.

3
00:00:55,940 --> 00:00:58,312
You like him, don't you? You like watching him

4
00:00:58,568 --> 00:01:01,569
- Don't be ridicolous!
- We are going to kill him. Understand?

5
00:01:01,822 --> 00:01:04,313
Morpheus believes, that he's The One.


...and so on. I am thinking that I am supposed to make a for loop, read the first number so the function knows where we are, then go to the second line (but how?) where the time is and sum it up with the number I entered at the start. Am I headed in the right direction here? How to make the function know I want to read the time (00:01:04,313) and change it?
>>
You need a function to increment time, you'll have to split into hours minutes seconds and milliseconds, increment them and add some ifs for the carry.

For the main loop you'll have to read line by line, if it's a line number just write it to the new file, next line is a timecode, you'll have to split both times and send them to the delay function and then write to the new file, then just copy all the following lines until it finds a line number and so on
>>
Okay this is what I've got so far, because someone on another website answered with that.

Now how do I proceed. I know I need to include:
ifstream subIn;
ofstream subOut;

also need to put cin >> (forhowmuchtimeyouwanttodelay) somewhere in there

then somehow implement everything.

#include <iostream>

using namespace std;

namespace nih{
struct time{
int millisecond; //easier to operate with
};

istream& operator>>(istream &in, time &t){
int h, min, sec, milli;
in>>h; in.get(); //ignore the ':'
in>>min; in.get(); //ignore the ':'
in>>sec; in.get(); //ignore the ',' (note that it uses , instead of .)
in>>milli;
t.millisecond = milli + sec*1000 + min*60*1000 + h*60*60*1000;
return in;
}
}

int main()
{
time start, end;
string arrow;
int id;
//...

while(cin >> id >> start >> arrow >> end){ //stream redirection
start += offset; //to be implemented
end += offset;
cout << id << start << arrow << end;

string line;
while(getline(cin, line) and not line.empty()) //the dialog ends with a blank line
cout << line << '\n';
}
}
>>
If you have to output in hh:mm:ss,ms format it makes no sense overloading >> to turn it into milliseconds since you'll have to overload the output operator to turn it back into a timestamp
>>
>>34196
while not (subIn.eof()){
subIn >> id >> start >> arrow >> end;
subOut << id << start + offset << arrow << end + offset;

string line;

do{
getline(subIn, line);
subout << line;
}while (line.compare ("\n") !=0)
}
>>
>>34254
so what am I supposed to do with this? Did you declared string line again on purpose? Am I supposed to delete the

while(cin >> id >> start >> arrow >> end){ //stream redirection
start += offset; //to be implemented
end += offset;
cout << id << start << arrow << end;

string line;
while(getline(cin, line) and not line.empty()) //the dialog ends with a blank line
cout << line << '\n';
}

and replace it with what you wrote?

Also thank you!
>>
>>34212
Yes I was wondering what does that even do. It returns "in" so I'm still figuring out what's the point
>>
why are you supposed to overload a standard operator just to parse a line like
>hh:mm:ss, mss --> hh:mm:ss, mss
>>
>>34357
how should i do it then?
>>
>>34360
What's wrong with getline()?

Why are you using C++ anyway?

What's the objective of the exercise? What facet of C++ are you supposed to be learning by doing this? Input streams? Objects? Why C++ is not a good substitute for Awk?

If I absolutely had to use C++, I'd use a loop that just did while(readline()), and then used a regular expression library to parse out the timestamps, and a pair of functions to convert the array of ints into milliseconds and back.
>>
>>34397
School assignment! We started learning C++ as our first programming language. Objective of the exercise is to input the file and work with it. We're learning about files so that is that. I will try to work around what you said, I just have to figure out how and what libraries!
>>
>>34408
also we have to do it using argv
>>
>>34408
No, that's the exercise of the exercise.

What are you supposed to be *learning*?

Assuming this is an exercise, they'll have taught you what you needed to know to do it, and then left you to do it.

So you should be solving the problem with whatever techniques you were taught.

And not, for example, observing that C++ is a superset of C, and solving the problem in C.
>>
>>34415
I guess what I'm saying is that you're going to be marked not on whether you solved the problem, but on whether or not you applied the techniques you were supposed to be learning.

So don't do it the best way or the way some guy said to, do it the way that shows you were paying attention the past week.
>>
>>34408
>We started learning C++ as our first programming language.
I'm so sorry.
Thread replies: 15
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.