Assignment1 OOP C++
-
Upload
zainzahid99 -
Category
Documents
-
view
1 -
download
0
description
Transcript of Assignment1 OOP C++
AIR UNIVERSITY
Faculty of Basic and Applied Sciences
Department of Computer Science & Engineering
Assignment No. 1
In this assignment you will write a C++ program to get student information
from user on run time and calculate student grade based on marks obtained.
In order to accomplish the task you are required to create a class named
Student which allows storing student information including (Roll No, Name,
Class Name, Total Marks and Grade). Class should facilitate to calculate
student grade based on provided marks (check grading rules given below). To
store student name inside class use two dimensional character array. Create
get and set methods to read/write property values as per required.
Grading rules are:
o 80 % and above is grade A
o From 65 % to 79 % is grade B
o From 50 % to 64 % is grade C
o From 40 % to 49 % is grade D
o Below 40 % is grade F
Program should facilitate user to perform at least following:
Take student details from user at run time (except grade)
- After filling in student details save this student instance in an array and ask
user if he / she want to enter details of another student.
- User can enter details of maximum 10 students
- After getting details of students from user, calculate grade (in a loop) of all
students added in array.
- Display details of all students and calculated grades in given format. You will
create a separate function which will accept student array as an argument to
display their details
- After displaying grades system should ask user to exit or repeat. If user
chooses to repeat, the whole process should start again.
Format to display student data:
*********************************************************************************
* Roll No * Name * Class * Marks * Grade *
*********************************************************************************
* 10001 * Haroon * BSCS * 78.00 * A *
* 10003 * Hamza * BEE * 87.00 * A *
* 10004 * Usman * BEE * 82.00 * A *
Code:
//============================================================================
// Name : Asignment1.cpp
// Author : Zain Zahid (150900)
// Version :
// Copyright : © ZAIN ZAHID (150900) ALL RIGHTS RESERVED
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
class student
{
private:
int rollno[10],marks[10],number;
char name[10][30],grade[10],classname[10][30];
public:
void getData()
{
int i=0,n;
while(n!=2&&i<10)
{
cout<<"Enter the Name of Student "<<i+1;
cin>>name[i];
cout<<"Enter the Roll no of Student "<<i+1;
cin>>rollno[i];
cout<<"Enter the Class Name of Student "<<i+1<<" i.e(BSCS-A) ";
cin>>classname[i];
cout<<"Enter the Marks of Student "<<i+1;
cin>>marks[i];
cout<<"Enter 1 to add data of other student otherwise Enter 2 to Stop Entering";
cin>>n;
i++;
}
number=i; //Number of Students
}
void setData()
{
for(int i=0;i<number;i++)
{
if(marks[i]>79)
grade[i]='A';
if(marks[i]>64&&marks[i]<80)
grade[i]='B';
if(marks[i]>49&&marks[i]<65)
grade[i]='C';
if(marks[i]>39&&marks[i]<50)
grade[i]='D';
if(marks[i]<40)
grade[i]='F';
}
}
void showGrades()
{
cout<<"*******************************************************************\n";
cout<<"* Rollno * Name * Class * Marks * Grade *\n";
cout<<"*******************************************************************\n";
for(int i=0;i<number;i++)
cout<<"* "<<rollno[i]<<" * "<<name[i]<<" * "<<classname[i]<<" * "<<marks[i]<<" * "<<grade[i]<<" *\n";
}
};
void displayData(student students)
{
students.showGrades();
}
int main() {
student s;
int x=0;
while(x!=2)
{
s.getData();
s.setData();
displayData(s);
cout<<"Enter 1 to continue the same process or Enter 2 to exit";
cin>>x;
}
return 0;
}