Friday, July 31, 2009

Pass by reference functions in C++?

write a pass by reference functions for 3 courses u take


the course name (without spaces)


number of creds


grade value (decimal number)





so far i got the value ret function right but im stuck my code so far is





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;string%26gt;


using namespace std;


//fn prototype for passing num of students in class


void DisplayStudent(double num, double answer);


void DisplayName(coursename%26amp;);














int main ()


{


double num,answer;


cout%26lt;%26lt;"Enter the total number of students in each class \n";


cin%26gt;%26gt;num;


answer=num;


cout%26lt;%26lt;"What course you want to take\n":


cin%26gt;%26gt;name;


//function call


DisplayStudent(answer,num);


DisplayName(coursename%26amp;)


return 0;


}


//function goes here


void DisplayStudent(double num,double answer)


{


cout%26lt;%26lt;" the total number of students="%26lt;%26lt;answer;


}


voidDisplayName(coursename%26amp;)


{ cout%26lt;%26lt;"what course"%26lt;%26lt;answer;


cin%26gt;%26gt;course;


}





if u can help much appreciated !!!!!!!!!!

Pass by reference functions in C++?
#include %26lt;iostream%26gt;





using namespace std;





int calculateGPA(double, double);





void main ()


{





char[] course;


double totalCredits = 0.0;


double totalPoints = 0.0;


double hours, grade;


int continue = 1;





//1 equates to true in C or C++, 0 equates to false


while(continue)


{


cout%26lt;%26lt;"Enter class: ";


cin%26gt;%26gt;course;


cout%26lt;%26lt;"\nEnter credit hours: ";


cin%26gt;%26gt;(double)hours;


cout%26lt;%26lt;"\nEnter course grade: ";


cin%26gt;%26gt;(double)grade;





//add to total credits for GPA calculation


totalCredits += hours;


//this is tricky, I know this calculation because Im a student


//you should know this to from report cards


totalPoints += (grade * hours);





cout%26lt;%26lt;"\nEnter 1 to add another class or 0 to quit";


cin%26gt;%26gt;(int)continue;





}//end while





//once user quits entering info, calculate statistics


cout %26lt;%26lt; "GPA = " %26lt;%26lt; calculateGPA(totalPoints, totalCredits);





}//end main








int calculateGPA(totalPoints, totalCredits)


{


return (int)(totalPoints/totalCredits);


}
Reply:This should be your function prototype:





void DisplayName( string %26amp;courseName );





Keep at it!


No comments:

Post a Comment