Sunday, August 2, 2009

Need another C or C++ code for...?

a simple structure named Students. This structure consists of three variables Name, GPA and TotalMarks. Now write three variables of data type Students. Get value from user for these three students and show them on screen.

Need another C or C++ code for...?
If I understand your question correctly this is


what you're looking for. =) Enjoy


%26lt;3





- Hex





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;conio.h%26gt; // For getch(); function





using namespace std;








int main()


{


struct Students


{


string Name;


char GPA[5];


char TotalMarks[5];


};








Students ST1;


cout %26lt;%26lt; "Student 1\n"


%26lt;%26lt; "Name: ";


getline(cin, ST1.Name);





cout %26lt;%26lt; "GPA: ";


cin.getline(ST1.GPA, 5);





cout %26lt;%26lt; "TotalMarks: ";


cin.getline(ST1.TotalMarks, 5);








Students ST2;


cout %26lt;%26lt; "\n\nStudent 2\n"


%26lt;%26lt; "Name: ";


getline(cin, ST2.Name);





cout %26lt;%26lt; "GPA: ";


cin.getline(ST2.GPA, 5);





cout %26lt;%26lt; "TotalMarks: ";


cin.getline(ST2.TotalMarks, 5);








Students ST3;


cout %26lt;%26lt; "\n\nStudent 3\n"


%26lt;%26lt; "Name: ";


getline(cin, ST3.Name);





cout %26lt;%26lt; "GPA: ";


cin.getline(ST3.GPA, 5);





cout %26lt;%26lt; "TotalMarks: ";


cin.getline(ST3.TotalMarks, 5);











cout %26lt;%26lt; "\n\n\t::Student Records:::\n"


%26lt;%26lt; "[Student - 1]\n"


%26lt;%26lt; "Name: " %26lt;%26lt; ST1.Name %26lt;%26lt; endl


%26lt;%26lt; "GPA: " %26lt;%26lt; ST1.GPA %26lt;%26lt; endl


%26lt;%26lt; "Total Marks: " %26lt;%26lt; ST1.TotalMarks





%26lt;%26lt; "\n\n[Student - 2]\n"


%26lt;%26lt; "Name: " %26lt;%26lt; ST2.Name %26lt;%26lt; endl


%26lt;%26lt; "GPA: " %26lt;%26lt; ST2.GPA %26lt;%26lt; endl


%26lt;%26lt; "Total Marks: " %26lt;%26lt; ST2.TotalMarks








%26lt;%26lt; "\n\n[Student - 3]\n"


%26lt;%26lt; "Name: " %26lt;%26lt; ST3.Name %26lt;%26lt; endl


%26lt;%26lt; "GPA: " %26lt;%26lt; ST3.GPA %26lt;%26lt; endl


%26lt;%26lt; "Total Marks: " %26lt;%26lt; ST3.TotalMarks;





getch();


}
Reply:Why don't you do your own homework? It's very educational, and (in this case) fun!


No comments:

Post a Comment