Ex.No:1 Student Database using Classes and Objects

AIM:

          To write a C++ program to create a student database using classes and objects.

ALGORITHM:

STEP 1: Start the program.

STEP 2: Declare the data members.

STEP 3: Define the data members outside of the class.

STEP 4: Read the student details ie. Rollno, Name, Mark1, Mark2, Mark3.

STEP 5: Calculate average of marks using

Avg = (m1+m2+m3)/3

STEP 6: Display the student record.

STEP 7: Stop the program.

PROGRAM CODE:

#include<iostream.h>
#include<conio.h>
class student
{
    char rno[10];
    char name[10];
    float m1,m2,m3;
    float avg;
    public:
    void read_data();
    void compute();
    void display();
};
void student::read_data()
{
    cout<<"  Enter the Student Roll Number :";
    cin>>rno;
    cout<<"  Enter the Student Name:";
    cin>>name;
    cout<<"  Enter the marks in three subjects:n";
    cin>>m1>>m2>>m3;
}
void student::compute()
{
    avg=(m1+m2+m3)/3;
}
void  student::display()
{
    cout<<"n ------------------------------------------------------n";
    cout<<name<<" Detailsn";
    cout<<"n ------------------------------------------------------n";
    cout<<"  Rollno is "<<rno;
    cout<<"n  Name is "<<name;
    cout<<"n  Mark1 is "<<m1;
    cout<<"n  Mark2 is "<<m2;
    cout<<"n  Mark3 is "<<m3;
    cout<<"n  Average mark of three subjects is "<<avg;
    cout<<"n ------------------------------------------------------n";
}
void main()
{
    student s[10];
    int n,i;
    clrscr();
    cout<<"n  Enter the number of Students:";
    cin>>n;
    for(i=0;i<n;i++)
    s[i].read_data();
    for(i=0;i<n;i++)
    s[i].compute();
    for(i=0;i<n;i++)
    s[i].display();
    getch();
}
OUTPUT:

student

RESULT:

                   Thus the C++ program for maintaining student database is written and executed successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *