write a program that counts the number of occurence of he operator( != ) in a given c++ program file.
Quiz 4Simple but tricky
Page 1 of 1
5 Replies - 3730 Views - Last Post: 09 January 2006 - 09:08 PM
Replies To: Quiz 4
#2
Re: Quiz 4
Posted 09 January 2006 - 04:11 PM
Aren't you getting tired of making quizes, that no one does anymore?
//Have read the entire file in to a string
//str contains the the file
size_t pos = 0;
int numofOccurance = 0;
while(pos != string::npos)
{
pos = str.find("!=", pos+1);
if(pos != string::npos)
{
numofOccurance++;
}
else
{
break;
}
//numofOccurance now contains the number of times != occurs in the string
#3
Re: Quiz 4
Posted 09 January 2006 - 06:07 PM
How do I know this isn't a homework question?
#5
Re: Quiz 4
Posted 09 January 2006 - 09:01 PM
HI guys, i cn c that u think i giv u guys my homework, well dats nt true, i cn do way better than that.and of course some of the solutions i give dem myself.i have finished this course with an A+.?im way pass that...neway i jus thot it cud be kinda kuul, to hv problems that will make u feel gud about urself.
back to the quiz...mrafcho i think ur program does count only the first != operator it sees always, if there are many it doesnt count them all.
i believe if u take the content character by charater it makes more sense.
example
in.open("text.txt");
in.get(prevchar);
in.get(currchar);
while( in )
{
if ( prevchar == '!' && currchar == '=' )
count++;
prevchar = currchar;
in.get(currchar);
}
okay guys this is it, the last quiz.....I will like to take some time and thank all the people that participated in all the quizez i posted...mrafcho in particular for solvn almost all tha problems, wekk done...Adios guys
back to the quiz...mrafcho i think ur program does count only the first != operator it sees always, if there are many it doesnt count them all.
i believe if u take the content character by charater it makes more sense.
example
in.open("text.txt");
in.get(prevchar);
in.get(currchar);
while( in )
{
if ( prevchar == '!' && currchar == '=' )
count++;
prevchar = currchar;
in.get(currchar);
}
okay guys this is it, the last quiz.....I will like to take some time and thank all the people that participated in all the quizez i posted...mrafcho in particular for solvn almost all tha problems, wekk done...Adios guys
#6
Re: Quiz 4
Posted 09 January 2006 - 09:08 PM
Nope, it works fine. I guess you should learn the string class.
Tested
Tested
This post has been edited by Mrafcho001: 09 January 2006 - 09:10 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|