10 Replies - 871 Views - Last Post: 21 February 2007 - 01:58 AM Rate Topic: -----

#1 Acura  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-January 07

Beginning C++

Posted 19 February 2007 - 11:50 AM

Hi every body...

pls guys i need help to start work in c++ im really confiused coz i dont know from where to start to learn ,,, in class i feel i cant understand any thing from the teacher,, :huh:

and i have 3 program to write and i dont know how to finish it ..

im waiting for help to learn

bbye

Is This A Good Question/Topic? 0
  • +

Replies To: Beginning C++

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Beginning C++

Posted 19 February 2007 - 12:02 PM

Here is a good place to begin:

http://www.cplusplus.com/doc/tutorial/

http://www.cprogramm...m/tutorial.html

If you have any specific questions we would be pleased to answer.
Was This Post Helpful? 0
  • +
  • -

#3 Acura  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-January 07

Re: Beginning C++

Posted 19 February 2007 - 12:31 PM

thanx Amadeus for ur help,,,

but still i need to finish the 3 programs before tomorow,,, im really confiused..

i will go throw the 2 sites u gives to me and i will try to do something before tomorow,,,

bbye
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Beginning C++

Posted 19 February 2007 - 12:37 PM

Well, as I mentioned, the members here would be more than happy to provide you with some guidance, but we need specific questions relating to the code to be able to properly help.
Was This Post Helpful? 0
  • +
  • -

#5 Acura  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-January 07

Re: Beginning C++

Posted 19 February 2007 - 12:57 PM

Thanx again dear

what i have to write is :
1- Find the alphabetical letter that stored in a file by position, for example using seek function ...

2-find the number of characters and lines in a stored file.

3-calculate the average of some numbers that stored in a file.

thats the 3 program i write some thing but still i dont know what to do. :ph34r:
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Beginning C++

Posted 19 February 2007 - 01:13 PM

If you would care to post what you have written so far, we can certainly help.
Was This Post Helpful? 0
  • +
  • -

#7 Acura  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-January 07

Re: Beginning C++

Posted 19 February 2007 - 01:17 PM

#include <iostream>
#include <fstream>

using namespace std;
int main()
{

int number=0, sum=0, avg;
ifstream infile;
infile.open("Average.doc");
infile>>avg;

   while(!infile.eof())
{
number = 0;
sum=0;
avg= sum / number;



infile>>number;
}

cout<<" the sum is : "<<sum<<endl;
cout<<" the avg is : "<<avg<<endl;
infile.close(); 
system("pause");
return(0);
   
}


this for average i dont know how to complete it
Was This Post Helpful? 0
  • +
  • -

#8 quim  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 182
  • Joined: 11-December 05

Re: Beginning C++

Posted 19 February 2007 - 01:51 PM

   while(!infile.eof())
{
number = 0;
sum=0;
avg= sum / number;



just by reading the code i found this mistake number = 0
then avg = sum/ number
CANNOT DEVIDE BY ZERO (remember the math)
I'll be back ;)

This post has been edited by quim: 19 February 2007 - 01:52 PM

Was This Post Helpful? 0
  • +
  • -

#9 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Beginning C++

Posted 19 February 2007 - 02:08 PM

I'm not near a compiler, but you may wish to look at something a little more like the following (not compiled, so it has not been checked)
#include <iostream>
#include <fstream>

using namespace std;
int main()
{

int number=0, sum=0, count = 0;
float avg;
ifstream infile;
infile.open("Average.doc");
infile>>number;

while(!infile.eof())
{
sum+=number;//adds the the number to the total
count++; //increases the number of numbers read by one
infile>>number;
}
avg= sum / count; //divides total by the number of numbers
cout<<" the sum is : "<<sum<<endl;
cout<<" the avg is : "<<avg<<endl;
infile.close();
system("pause");
return(0);

}


Of course, this code performs no error checking, and could still have many errors - I'm writing it on the fly.

this does also not take into account how the data in your file is structured.
Was This Post Helpful? 0
  • +
  • -

#10 alrashdi86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-February 07

Re: Beginning C++

Posted 20 February 2007 - 02:34 AM

yes me also i am having a big problem in c++ we are on the same path acura :D
Was This Post Helpful? 0
  • +
  • -

#11 Acura  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-January 07

Re: Beginning C++

Posted 21 February 2007 - 01:58 AM

hi again and thanx for all ... isolve the problem ...
#include <iostream>
#include <fstream>

using namespace std;
int main()
{

int number=0, sum = 0, avg,count=0;
fstream infile;
infile.open("avg.txt",ios::in);
infile>>number;
while(!infile.eof())
{

sum+=number;
infile>>number;
count++;
}

infile.close(); 
avg = sum/count;
cout<<" the count is : "<<count<<endl;
cout<<" the sum is : "<<sum<<endl;
cout<<" the avg is : "<<avg<<endl;

system("pause");
return(0);
   
}



:D finally i did it...

thanx again for all

bbye
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1