المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : إيرور بالبرنامج _ structur ~



رثاء
05-23-2011, 09:53 PM
سلام
شخباركم ؟
يصير أحد يكتشف لنا الخطأ
مو راضي يشتغل البرنامج
. .

هاي السؤال
ITCS102 Assignment#2
Structures I

1. Define a structure called Student with data members such as:
string name; int cpr; int age; float gpa;

2. Write a function called readStudent ( ….) that receives a parameter by reference(address) called aStud of type Student. Using cout/cin, prompt the user to read all the data members of aStud.
3. Write a function called displayStudent( ….) that receives a parameter by copy called aStud of type Student. UsThe function display tall the aStud information in a formatted way.

4. Write a function called bestStudent(…)that receives two parameters by copy called aStud1 and aStud2 both of type Student. The function output the name of the one who got the highest gpa.


5. write a main function where you:

5.1 declare two variables called stud1 and stud2 both of type Student.
5.2 Call the function readStudent to read data in stud1.
Call the function readStudent to read data in stud2.
5.3 Call the function bestStudent to see which of stud1 and stud2 got a better gpa.
5.4 Call the function displayStudent to output stud1 info.
5.5 Call the function displayStudent to output stud2 info.


. ...............................

هاي الجواب
# include<iostream>
using namespace std;
struct Student {
string name;
int cpr;
int age;
float gpa;
};
void readStudent ( Student& aStud ){
cout << " read all the data members of aStud" << endl;
cin >> aStud.name << endl;
cin >> aStud.cpr << endl;
cin >> aStud.age << endl;
cin >> aStud.gpa << endl;
}
void displayStudent ( Student aStud){
cout << aStud.name << endl;
cout << aStud.cpr << endl;
cout << aStud.age << endl;
cout << aStud.gpa << endl;
}
void bestStudent ( Student aStud1, Student aStud2){
if ( aStud1.gpa > aStud2.gpa)
cout << aStud1.name;
else
cout << aStud2.name;
}
int main (){
Student stud1, stud2;
readStudent ( stud1);
readStudent (stud2);
bestStudent ( stud1, stud2);
displayStudent (stud1);
displayStudent( stud2);
return 0;
}