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

طلب مساعدة في functions

بدأه Mac OS X في 5 نوفمبر 2012 · 4 رد · 551 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

لدي وخطأ دائماً مايظهر ولا أعرف ماهي الطريقة لتجنبه

هذا هو السؤال

Write a program that reads student's names followed by their ID and test scores. student data should be stored in a struct variable of type studenttype which has 3 members: name ,ID, and test score. Declare array ITCS104students of size 7 of elements of type studenttype.

add the following functions to your program:

  • a function to read all members of your array.
  • a function to print name and ID of the student with the highest test score.

ماهو تقييمكم لإجابتي وأذا كان يوجد أخطاء أرجو توضيحها لي مع جزيل الشكر

الجواب

# include <iostream>
# include <string>
using namespace std;
{

	struct studenttype
	{
		string name;
		long ID;
		float testscore;
	};
	void Readallmembers(studenttype list[])
	{
		cout <<"Enter Name ID and test score: ";
		cin >> arr.name >> arr.ID >> arr.testScore;
	}
	void Print(studenttype list[])
	{
		loc=0;
		for(int i=1 ; i<5 ; i++)
			if(list.testscore < list[loc].testscore)
				loc=i;
	}
		cout << list[loc].name << list[loc].ID << list[loc].testscore;
		int main()
		{
			studenttype ITCS104[5];
			for(int i=0 ; i<5 ; i++)
            Readallmembers(ITCS104student);
			print(ITCS104student);
			return 0;
		}

}

الخطأ error C2447: '{' : missing function header (old-style formal list?)

السطر الرابع

تم تعديل هذه المشاركة بواسطة محمد عودة في 6 نوفمبر 2012 في 19:47 — السبب: تنسيق النص

#3
#include <iostream>
#include <string>

using namespace std;

typedef struct Student
{
    Student() : name(""),ID(0),testScore(0){}
    string name;
    long ID;
    float testScore;
} Student;

void Readallmembers(Student arr[],unsigned int len)
{
    cout <<"Enter Name ID and test score : " << endl;
    unsigned int i = 0;
    while(i < len)
    {
        cin >> arr.name >> arr.ID >> arr.testScore;
        ++i;
    }
}

void PrintBest(Student list[],unsigned int len)
{
    Student best;
    for(unsigned int i = 0; i < len; ++i)
    {
        if(list.testScore >= best.testScore)
        {
            best = list;
        }
    }

    cout << "\nStudent : " << best.name << " whose ID : " << best.ID << " has the best score : " << best.testScore << endl;
}

int main()
{
    const int LENGTH = 7;
    Student ITCS104[LENGTH];

    Readallmembers(ITCS104, LENGTH);
    PrintBest(ITCS104, LENGTH);
    return 0;
}


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#4

يمكن أن يكون الكود:

اقتباس
typedef struct Student {

   Student() : name(""), ID(0), testScore(0) {
	}
	string name;
	long ID;
	float testScore;
} Student;

بالطريقة:

 typedef struct Student {

  //  Student() : name(""), ID(0), testScore(0) {	
	string name;
	long ID;
	float testScore;
} Student;

حتى ﻻ يحدث ارباك للدارس

تم تعديل هذه المشاركة بواسطة محمد عودة في 6 نوفمبر 2012 في 20:07

post-15367-027053900%201340345097.gifpost-15367-087183200%201340344597.gif
post-247365-0-10080400-1379403554_thumb.

#5

Constructor هام لعملية Initialization بدلا من جعل المتغيرات static


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

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