9.11.14

OOP : Excercise-6 : Write a Object Oriented Program to Display Studnet Information

Create a class named as Student containing the following data members:
--Roll_no
--Name
--Marks1, Marks2, Marks3
Write necessary member functions:
1. to accept details of all students
2. to display details of one student
3. to display details of all students(Use Function overloading).
 (Use Function overloading)

15 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Who asked your information? Don't abuse this blog.

      Delete
  2. //Reference page: http://www.c-programming-practice.blogspot.com/2014/02/file-sample.html
    //Mujaffor Ali Sumon
    #include
    #include
    #include
    #include
    #include
    #include

    using namespace std;

    class student
    {
    public:

    char first_name[50], last_name[50];
    int roll;
    float ban_mark,eng_mark,mat_mark;

    };

    int main()
    {

    student inf;

    char option, select;


    FILE *fp;
    fp=fopen("users.txt","rb+");

    if (fp == NULL)
    {
    fp = fopen("users.txt","wb+");

    return 0;

    }


    while(1)
    {

    system("cls");
    cout << "\n\n";
    cout << "\t\t****** INFORMATION OF STUDENTS ******";
    cout << "\n\n";
    cout << "\n \t\t 1. Add Students";
    cout << "\n \t\t 2. Show Records";
    cout << "\n \t\t 3. Exit";
    cout << "\n\n";
    cout <<"\t Select What you want:> inf.first_name;
    cout << "Last Name : ";
    cin >> inf.last_name;
    cout << "Roll No : ";
    cin >> inf.roll;
    cout << "Marks of Bangla : ";
    cin >> inf.ban_mark;
    cout << "Marks of English : ";
    cin >> inf.eng_mark;
    cout << "Marks of Mathmetic : ";
    cin >> inf.mat_mark;

    fwrite(&inf,sizeof(inf),1,fp);
    cout << "\n Add Another Record (Y/N) ";
    fflush(stdin);
    option = getchar();
    }
    break;
    case '2':
    system("cls");
    rewind(fp);
    cout << "=== View the Records in the Database ===";
    cout << "\n";
    while (fread(&inf,sizeof(inf),1,fp) == 1)
    {
    cout << "\n";
    cout <<"\t Name of Students : "<< inf.first_name << setw(5)<< inf.last_name;
    cout << "\n";
    cout <<"\t Roll No : " <<inf.roll;
    cout << "\n";
    cout <<"\t Bangla : " <<inf.ban_mark;
    cout << "\n";
    cout << "\t English : " <<inf.eng_mark;
    cout << "\n";
    cout <<"\t Mathmetics : " <<inf.mat_mark<<endl;
    cout<<"\t" <<endl<<"================================="<<endl;
    }
    cout << "\n\n";
    system("pause");
    break;

    case '3':
    system("cls");
    fclose(fp);
    cout << "\n\n";
    cout << "\t\t********************************************************"<<endl;
    cout << "\t\t* THANKS BY MUJAFFOR ALI SUMON. *"<<endl;
    cout << "\t\t********************************************************"<<endl;
    cout << "\n\n";
    exit(0);
    }
    }

    system("pause");
    return 0;
    }

    ReplyDelete
    Replies
    1. You are requested to add header file, if you use any header rather then . If blog system does not support it to write then write using comment tag as like //

      Delete
    2. noted. if you found another way or easy way then you may submit again. thanks for your participation on a hard/difficult problem.
      try to use header file as like # include isstream [do not use any < or > bracket]

      Delete
    3. Here include Header File.

      #include iostream
      #include stdio.h
      #include cstdlib
      #include conio.h
      #include iomanip
      #include cstring

      Delete
    4. Dear Sir,
      Please visit below site for complete program:

      http://itlearn24.blogspot.com/2014/11/write-object-oriented-program-to.html

      Delete
  3. //Update using function & class

    /*
    Reference page: http://www.c-programming-practice.blogspot.com/2014/02/file-sample.html
    #include
    #include
    #include
    #include
    #include
    #include
    Visit this page http://www.c-plus-tutorial.blogspot.com/2014/11/oop-excercise-4-write-object-oriented.html
    */

    #include
    #include
    #include
    #include
    #include
    #include
    using namespace std;

    class student
    {
    public:
    char first_name[30], last_name[30];
    int roll;
    float ban_mark,eng_mark,mat_mark;
    char x_last_name[30];

    void body()
    {
    system("cls");//
    cout << "\n\n";
    cout << "\t\t****** INFORMATION OF STUDENTS ******";
    cout << "\n\n";
    cout << "\n \t\t 1. Add Students";
    cout << "\n \t\t 2. Search by first Name ";
    cout << "\n \t\t 3. Show all Records";
    cout << "\n \t\t 4. Delete Records";
    cout << "\n \t\t 5. Exit";
    cout << "\n\n";
    cout <<"\t Select What you want:<1-5> ";

    }
    void getdata()
    {
    system("cls");
    cout << "First Name : ";
    cin >> first_name;
    cout << "Last Name : ";
    cin >> last_name;
    cout << "Roll No : ";
    cin >>roll;
    cout << "Marks of Bangla : ";
    cin >> ban_mark;
    cout << "Marks of English : ";
    cin >> eng_mark;
    cout << "Marks of Mathmetic : ";
    cin >> mat_mark;

    }

    void showdata()
    {
    cout<< "\n";
    cout <<"\t Name of Students : "<< first_name << setw(15)<< last_name;//
    cout << "\n";
    cout <<"\t Roll No : " <> xfirst_name;

    rewind(fp);
    while (fread(&inf,sizeof(inf),1,fp)==1)
    {
    if (strcmp(inf.first_name,xfirst_name)== 0)
    {
    inf.showdata();

    break;
    }
    else
    cout<> xfirst_name;

    ft = fopen("temp.dat", "wb");

    rewind(fp);
    while (fread (&inf, sizeof(inf),1,fp) == 1)

    if (strcmp(inf.first_name,xfirst_name) != 0)
    {
    fwrite(&inf,sizeof(inf),1,ft);
    }
    fclose(fp);
    fclose(ft);
    remove("users.txt");
    rename("temp.dat","users.txt");

    fp=fopen("users.txt","rb+");

    cout << "\n Delete option Record (Y/N) ";
    fflush(stdin);
    option = getchar();
    }

    break;

    case '5':
    fclose(fp);
    system("cls");
    cout << "\n\n";
    cout << "\t\t********************************************************"<<endl;
    cout << "\t\t* THANKS BY 46TH BATCH. *"<<endl;
    cout << "\t\t********************************************************"<<endl;
    cout << "\n\n";
    exit(0);
    }
    }


    system("pause");
    return 0;
    }

    ReplyDelete
  4. Very good information and thanks for posting this here! Please keep sharing more information like this further in future. You can find more information on C++ Tutorials in the following link.

    CPP Tutorials online

    ReplyDelete
  5. //jamil zilani
    //201930092

    #include
    using namespace std;
    class student
    {
    private:

    char name[20],regd[10],branch[10];
    int sem;
    public:
    void input();
    void display();


    };
    void student::input()
    {
    cout<<"Enter Name:";
    cin>>name;
    cout<<"Enter Regdno.:";
    cin>>regd;
    cout<<"Enter Branch:";
    cin>>branch;
    cout<<"Enter Sem:";
    cin>>sem;
    }
    void student::display()
    {
    cout<<"\nName:"<<name;
    cout<<"\nRegdno.:"<<regd;
    cout<<"\nBranch:"<<branch;
    cout<<"\nSem:"<<sem;
    }
    int main()
    {
    student s;
    s.input();
    s.display();
    }

    ReplyDelete
  6. https://drive.google.com/file/d/1Rhc8tMngWj4oVXDAW2k6akC-o087Jj5X/view?usp=sharing

    ReplyDelete
  7. FARJANA KAMAL KONOK
    201930701

    using namespace std;
    class student
    {
    private:
    char name[20],regd[10],branch[10];
    int sem;
    public:
    void input();
    void display();
    };
    void student::input()
    {
    cout<<"Enter Name:";
    cin>>name;
    cout<<"Enter Regdno.:";
    cin>>regd;
    cout<<"Enter Branch:";
    cin>>branch;
    cout<<"Enter Sem:";
    cin>>sem;
    }
    void student::display()
    {
    cout<<"\nName:"<<name;
    cout<<"\nRegdno.:"<<regd;
    cout<<"\nBranch:"<<branch;
    cout<<"\nSem:"<<sem;
    }
    int main()
    {
    student s;
    s.input();
    s.display();
    }

    ReplyDelete
  8. //Taslima akter
    //id:202010462
    Batch:63
    #include
    using namespace std;
    class student
    {
    private:
    char name [20],id[10],bathch[10];
    int sem;
    public:
    void input();
    void display();
    };
    void student:input()
    {
    cout<<"enter name:";
    cin>>name;
    cout<<"enter id:";
    cin>>id;
    cout<<"enter bathch:";
    cin>>batch;
    cout<<"enter sem:";
    cin>>sem;
    }
    void student:display()
    {
    cout<<"\n name:"<<name:
    cout<<"\n id:"<<id:
    cout<<"\n bathch :"<<batch:
    cout<<"\n sem:"<<sem:
    }
    int main()
    {
    student s:
    s.input ():
    s.display ():
    }

    ReplyDelete
  9. //Murshida
    //id:202010463
    //Batch:63
    #include
    class student
    {
    char name[20];
    int batch;
    int id;
    };
    int main ()
    {
    student s;
    cout<<"enter information,"<>s.name ;
    cout<<"enter bathch :";
    cin>>s.batch;
    cout<<"enter id:";
    cin>>s.id;

    cout<<"\n display information, "<<endl;
    cout<<"name:"<<s.name<<endl;
    cout<<"batch:"<<s.bathch<<endl;
    cout<<"id:"<<s.id<<endl;

    return 0
    }

    ReplyDelete
  10. ///Tisha
    ///201930034
    #include
    #include
    #include
    #include
    #include
    #include
    using namespace std;
    class student
    {
    public:
    char first_name[30], last_name[30];
    int roll;
    float ban_mark,eng_mark,mat_mark;
    void body()
    {
    system("cls");
    cout << "\n\n";
    cout << "\t\t*Identify of students *";
    cout << "\n\n";
    cout << "\n \t\t 1. Add Students:";
    cout << "\n \t\t 2. Search by first Name :";
    cout << "\n \t\t 3. Show all Records:";
    cout << "\n \t\t 4. Delete Records:";
    cout << "\n \t\t 5. Exit:";
    cout << "\n\n";
    cout <<"\t Select anything:<1-5>: ";
    }
    void getdata()
    {
    system("cls");
    cout << "First Name : ";
    cin >> first_name;
    cout << "Last Name : ";
    cin >> last_name;
    cout << "Roll No: ";
    cin >>roll;
    cout << "Marks of Bangla : ";
    cin >> ban_mark;
    cout << "Marks of English : ";
    cin >> eng_mark;
    cout << "Marks of Math : ";
    cin >> mat_mark;
    }
    void showdata()
    {
    cout<< "\n";
    cout <<"\t Name of Students : "<< first_name << setw(8)<< last_name;
    cout << "\n";
    cout <<"\t Roll No: " <> xfirst_name;
    rewind(fp);
    while (fread(&inf,sizeof(inf),1,fp)==1)
    {
    if (strcmp(inf.first_name,xfirst_name)== 0)
    {
    inf.showdata();
    break;
    }
    else
    cout<> xfirst_name;
    ft = fopen("temp.dat", "wb");
    rewind(fp);
    while (fread (&inf, sizeof(inf),1,fp) == 1)
    if (strcmp(inf.first_name,xfirst_name) != 0)
    {
    fwrite(&inf,sizeof(inf),1,ft);
    }
    fclose(fp);
    fclose(ft);
    remove("users.txt");
    rename("temp.dat","users.txt");
    fp=fopen("users.txt","rb+");
    cout << "\n Delete option Record (Y/N) ";
    fflush(stdin);
    option = getchar();
    }
    break;

    case '5':
    fclose(fp);
    system("cls");
    cout << "\n\n";
    cout << "\t\t**"<<endl;
    cout << "\t\t*DONE*"<<endl;
    cout << "\t\t***"<<endl;
    cout << "\n\n";
    }
    }

    return 0;
    }

    ReplyDelete

Comment Here