ABA


"בעייה בקומפליזציה של תכנה ב c++ (ל''ת)"
גירסת הדפסה        
קבוצות דיון פיתוח, תיכנות ובניית אתרים נושא #15385 מנהל    סגן המנהל    מפקח   Winner    צל"ש   מומחה  
אשכול מספר 15385
MiZe 
חבר מתאריך 16.9.08
8898 הודעות
   01:53   23.06.09   
אל הפורום  
  בעייה בקומפליזציה של תכנה ב c++ (ל''ת)  
 
כתבתי את התכנית הזו:


// reading a file
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv)
{
int avg();
int app();
void write();
char word,filename;
int j=0,num, option;


cout << "1 - count words from file 2 - write to file 3 - average number at file - : ";
cin >> option;

if( option == 1 )
{
j = app();
cout << "The word is in the file " << j << " times" << endl;
}

if ( option == 2 )
{
write();
}

if (option == 3)
{
cout << avg() << endl;
}


system("PAUSE");
return EXIT_SUCCESS;


}
int app ( char filename )
{ char word;
int count=0;
fstream inFile;

cout<<"Enter file name:"<<endl;
cin>>filename;
cout<<"Enter a word :"<<endl;
cin>>word;
inFile.open(filename, ios::in);


if( !(inFile.is_open()))
{
cout<< "cannot open file"<<filename<<endl;
exit(1);
}

else
{
while(!(inFile.eof()))
{
inFile >> word;
count = count + 1;
}
}

return (count);
}
void write()
{
int num;
char filename;

cout<<"Enter file name:"<<endl;
cin>>filename;
ofstream makefile(filename, ios::out);

cout<<"Enter Num"<<endl;

while (cin>>num)
{
cout << "Enter num" << endl;
cin >> num;
makefile << num << endl;
}

}

int avg()
{
int average = 0;
int count = 0;
int num;
char filename;

cout<<"Enter file name:"<<endl;
cin>>filename;
ifstream open(filename, ios::in);

while(open>>num)
{
open >> num;
count++;
average += num;
}

average = average / count;
return(average);
}

וזה לא מתקמפל משום מה ..
זה רושם לי ארור מוזר :

יש לי למישהו מושג הבעיה ?

תודה


                                שתף        
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד

  האשכול     מחבר     תאריך כתיבה     מספר  
  מה זה ldan192  23.06.09 06:50 1
     ונקציה עם פרמטרים לא מוצהרים תמיד עובד לי .. MiZe  23.06.09 10:16 2
         לא יודע מאיפה הבאת את זה... אבל הקוד צריך להראות ככה: ldan192  23.06.09 13:55 3

       
ldan192 
חבר מתאריך 14.9.08
95119 הודעות
   06:50   23.06.09   
אל הפורום  
  1. מה זה  
בתגובה להודעה מספר 0
 
Int avg() ו-int app() בהצהרות בתחילת הפונקציה בדיוק?
ולמה השתמש ב-app מבלי להכניס פרמטרים (לפי הגדרת הפונקציה)

וגם את ה-Main תרשום בסוף הקוד, לא בתחלה, או שתצהיר על הפונקציות מראש.


בברכה,
עידן


                                                         (ניהול: מחק תגובה)
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד
MiZe 
חבר מתאריך 16.9.08
8898 הודעות
   10:16   23.06.09   
אל הפורום  
  2. ונקציה עם פרמטרים לא מוצהרים תמיד עובד לי ..  
בתגובה להודעה מספר 1
 
ותמיד ה main למעלה ..

מה הכוונה שיהיה למטה ?


                                                         (ניהול: מחק תגובה)
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד
ldan192 
חבר מתאריך 14.9.08
95119 הודעות
   13:55   23.06.09   
אל הפורום  
  3. לא יודע מאיפה הבאת את זה... אבל הקוד צריך להראות ככה:  
בתגובה להודעה מספר 2
 

// reading a file
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <stdlib.h>

using namespace std;

int app ( char filename ) ;
void write();
int avg();

int main(int argc, char *argv)
{
char word,filename;
int j=0,num, option;


cout << "1 - count words from file 2 - write to file 3 - average number at file - : ";
cin >> option;

if( option == 1 )
{
j = app(filename);
cout << "The word is in the file " << j << " times" << endl;
}

if ( option == 2 )
{
write();
}

if (option == 3)
{
cout << avg() << endl;
}


system("PAUSE");
return EXIT_SUCCESS;


}
int app ( char filename )
{ char word;
int count=0;
fstream inFile;

cout<<"Enter file name:"<<endl;
cin>>filename;
cout<<"Enter a word :"<<endl;
cin>>word;
inFile.open(filename, ios::in);


if( !(inFile.is_open()))
{
cout<< "cannot open file"<<filename<<endl;
exit(1);
}

else
{
while(!(inFile.eof()))
{
inFile >> word;
count = count + 1;
}
}

return (count);
}
void write()
{
int num;
char filename;

cout<<"Enter file name:"<<endl;
cin>>filename;
ofstream makefile(filename, ios::out);

cout<<"Enter Num"<<endl;

while (cin>>num)
{
cout << "Enter num" << endl;
cin >> num;
makefile << num << endl;
}

}

int avg()
{
int average = 0;
int count = 0;
int num;
char filename;

cout<<"Enter file name:"<<endl;
cin>>filename;
ifstream open(filename, ios::in);

while(open>>num)
{
open >> num;
count++;
average += num;
}

average = average / count;
return(average);
}

לא ניסיתי לקמפל אבל אילו הבעיות החמורות שבלטו בשאלה.
לא הבנתי מה ניסית אבל לעשות עם ההצהרות בתחילה המיין. זה לא טיפוס לפונקציה ולא כלום...


בברכה,
עידן


                                                         (ניהול: מחק תגובה)
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד

תגובה מהירה  למכתב מספר: 
 
___________________________________________________________________

___________________________________________________________________
למנהלים:  נעל | תייק בארכיון | מחק | העבר לפורום אחר | מחק תגובות | עגן אשכול
       



© כל הזכויות שמורות ל-רוטר.נט בע"מ rotter.net