Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

C++ example to Insert, Deleted, Search students record using class

//============================================================================
// Name        : DFS_AssignmentNo1.cpp
// Author      : Rushikesh
// Version     :
// Copyright   : @rushikesh
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
#define MAX 100

class LinearArray {
public:
    long int ACN;
    string FNAME, LNAME;
    int FEES, YEAR;
    void insert();
    void display();
    //void searchbyyear(int year);
    //void searchbyfees(int fee);
};

void LinearArray::insert()
{
    cout << "\n************************************************************";
    cout << "\nEnter the Adhar Card No.:";
    cin >> ACN;
    cout << "\nEnter the first name:";
    cin >> FNAME;
    cout << "\nEnter the Last name:";
    cin >> LNAME;
    cout << "\nEnter the fees:";
    cin >> FEES;
    cout << "\nEnter the Year:";
    cin >> YEAR;
    cout << "\n************************************************************";
}

void LinearArray::display()
{
    cout << "\n************************************************************";
    cout << "\nAdhar card NO.=" << ACN;
    cout << "\nFirst Name=" << FNAME;
    cout << "\nLast name=" << LNAME;
    cout << "\nFees=" << FEES;
    cout << "\nYear=" << YEAR;
    cout << "\n************************************************************";
}

int main()
{
    static int STRENGTH = 0;
    LinearArray a[30];
    int ch1, n, fee, year, temp = 0;
    char ch2;
    do {
        cout << "************************************************************";
        cout << "\n1.Insert record\n2.Display records\n3.Search records by using Fees\n4.Search by using Year";
        cout << "\n************************************************************";
        cout << "\nEnter your choice:";
        cin >> ch1;
        switch (ch1) {
        case 1:
            cout << "\nHow many records you want to insert...?";
            cin >> n;
            temp += n;
            while (STRENGTH < temp) {
                a[STRENGTH].insert();
                STRENGTH++;
            }
            break;
        case 2:
            for (int i = 0; i < STRENGTH; i++) {
                a[i].display();
            }
            break;
        case 3:
            cout << "\nEnter the fees:";
            cin >> fee;
            cout << "\nDetails of the Students whose Fees are " << fee << " and more than " << fee << ":";
            for (int i = 0; i < STRENGTH; i++) {
                if (a[i].FEES >= fee) {
                    cout << "\nAdhar card NO.=" << a[i].ACN;
                    cout << "\nFirst Name=" << a[i].FNAME;
                    cout << "\nLast name=" << a[i].LNAME;
                    cout << "\nYear=" << a[i].YEAR;
                }
            }
            break;
        case 4:
            cout << "\nEnter the year:";
            cin >> year;
            cout << "\nDetails of the Students whose year is " << year;
            for (int i = 0; i < STRENGTH; i++) {
                if (a[i].YEAR >= year) {
                    cout << "\n************************************************************";
                    cout << "Adhar card NO.=" << a[i].ACN;
                    cout << "First Name=" << a[i].FNAME;
                    cout << "Last name=" << a[i].LNAME;
                    cout << "Fees=" << a[i].FEES;
                    cout << "\n************************************************************";
                }
            }
            break;
        default:
            cout << "\nInvalid Choice!!!";
            break;
        }
        cout << "\nDo you want to continue...?(Y/N):";
        cin >> ch2;
    } while (ch2 == 'Y' || ch2 == 'y');
    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.