Quiz 4

Simple but tricky

Page 1 of 1

5 Replies - 3730 Views - Last Post: 09 January 2006 - 09:08 PM Rate Topic: -----

#1 bluesuus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 65
  • Joined: 26-December 05

Quiz 4

Posted 09 January 2006 - 10:51 AM

write a program that counts the number of occurence of he operator( != ) in a given c++ program file.
Is This A Good Question/Topic? 0
  • +

Replies To: Quiz 4

#2 Mrafcho001  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 40
  • View blog
  • Posts: 769
  • Joined: 01-November 05

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



Was This Post Helpful? 0
  • +
  • -

#3 Jessehk  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 24
  • Joined: 06-January 06

Re: Quiz 4

Posted 09 January 2006 - 06:07 PM

How do I know this isn't a homework question?
Was This Post Helpful? 0
  • +
  • -

#4 Mrafcho001  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 40
  • View blog
  • Posts: 769
  • Joined: 01-November 05

Re: Quiz 4

Posted 09 January 2006 - 07:18 PM

It probably is
Was This Post Helpful? 0
  • +
  • -

#5 bluesuus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 65
  • Joined: 26-December 05

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
Was This Post Helpful? 0
  • +
  • -

#6 Mrafcho001  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 40
  • View blog
  • Posts: 769
  • Joined: 01-November 05

Re: Quiz 4

Posted 09 January 2006 - 09:08 PM

Nope, it works fine. I guess you should learn the string class.

Tested

This post has been edited by Mrafcho001: 09 January 2006 - 09:10 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1