الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

برنامج فيه خطأ

مغلق
بدأه مبرمجة ++C في 6 نوفمبر 2004 · 9 رد · 598 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

لدي ثلاث ملفات فيه ست اخطاء حاولت تعديلها ولكن لم استطع ارجو المساعدة

وسوف اعطيكم الملفات الاصلية بدون تعديلي

debugging07.cpp

#2

الملف الثاني

student.cpp

#3

الملف الثالث

student.h

#4

بانتظار مساعدتكم

ارجو ان لا تخيبو ا ظني

فانا عدة مرات احتا ج مساعدة ولا اجد احد يرد علي

شاكرة لكم

#5

السلام عليكم

إن شاء الله هالمرة ما نخيب ظنك

اليك الحل بعد التعديل وقارني بنفسك لتعرفي سبب الاخطاء

// Chapter 7 of C++ How to Program
// Debugging Problem (student.h)

#include <iostream>
#include <iomanip>
#include <cstring>

using namespace std;
// class Student definition
class Student {

public:
   Student( const char * );
   ~Student();
   void displayGrades() const;
   void addGrade( int );
   static int getNumStudents(){return numStudents; }
   

private:
   int *grades;
   char *name;
   int numGrades;
   static int numStudents;
   int idNum;

   
}; // end class Student

int Student::numStudents = 0;

// Chapter 7 of C++ How to Program
// Debugging Problem (student.cpp)
#include "student.h"

// constructor
Student::Student( const char *nPtr )
{
   grades = new int[ 1 ];
   grades[ 0 ] = 0;
   name = new char[ strlen( nPtr ) + 1 ];
   strcpy( name, nPtr );
   numGrades = 0;
   numStudents++;

   cout << name <<" has been added\n";

} // end class Student constructor

// destructor
Student::~Student()
{
   cout << name << " has been deleted\n";
   delete grades;
   delete name;
   numStudents--;

} // end class Student destructor

// function displayGrades definition
void Student::displayGrades() const
{
   cout << "Here are the grades for " << name << endl;
   
   // output each grade
   for ( int i = 0; i < numGrades; i++ )
      cout << setw( 5 ) << grades[ i ]<<endl;

 } // end function displayGrades

// function addGrade definition
void Student::addGrade( int grade ) 
{
   int *temp = new int[numGrades+1];
   
   for ( int i = 0; i < numGrades; i++ )
   {temp[ i ] = grades[ i ];cout<<temp;}
   numGrades++;
   temp[ i ] = grade;
   
   delete grades;
   grades = new int[numGrades];
   for ( int i = 0; i < numGrades; i++ )
   { grades[ i ] = temp[ i ];}
   
   delete temp;
   
} // end function addGrade

int main() 
{
	cout << "There are currently " << Student::getNumStudents()
        << " students\n\n";

   Student *s1Ptr = new Student( "Student 1" );

   s1Ptr->addGrade( 100 );
   s1Ptr->addGrade( 75 );
   s1Ptr->addGrade( 89 );
   s1Ptr->displayGrades();

   Student *s2Ptr = new Student( "Student 2" );
   s2Ptr->addGrade( 83 );
   s2Ptr->addGrade( 92 );
   s2Ptr->displayGrades();

   Student s3( "Student 3" );
   s3.addGrade( 62 );
   s3.addGrade( 91 );
   s3.displayGrades();

   cout << "There are currently " << Student::getNumStudents()
        << " students\n\n";

   delete s2Ptr;
   delete s1Ptr;

   return 0;

} // end main
#6

جزاك الله كل خير

#7

جربته وماضبط

يكتب لي redfintion i

#8

لم يتعدل الخطأ

ارجو المساعدة لانه لم ينجح عند عمل الرن

#9

plz help me in this errors

#10

السلام عليكم

أنا جربت البرنامج على الvc.net وهو شغال 100%

يمكن المشكلة في الكومبايلر

مع تحياتي

هذا الموضوع مغلق.

مواضيع مشابهة