Untitled

 avatar
unknown
plain_text
5 months ago
2.1 kB
133
Indexable
#include <iostream>
#include <cstring> 
using namespace std;

class student
{
private:
    char name[50];
    int year;
    char section;
    char rollno[15];
    char address[100];

public:

    student()
    {

    }


    student(const char name1[50], const char rollno1[15], const char address1[100])
    {
        strcpy(this->name, name1);
        strcpy(this->rollno, rollno1);
        strcpy(this->address, address1);
    }

    student(const student &s)
    {
        strcpy(this->name, s.name);
        strcpy(this->rollno, s.rollno);
        strcpy(this->address, s.address);
        this->section = s.section;
        this->year = s.year;
    }

    void get_all_data()
    {
        cout << "Enter name: ";
        cin >> name;
        cout << "Enter rollno: ";
        cin >> rollno;
        cout << "Enter address: ";
        cin >> address;
        cout << "Enter year: ";
        cin >> year;
        cout << "Enter section: ";
        cin >> section;
    }

    void print_record()
    {
        cout << "\nName: " << name;
        cout << "\nYear: " << year;
        cout << "\nSection: " << section;
        cout << "\nRoll No: " << rollno;
        cout << "\nAddress: " << address << endl;
    }
};

int main(void)
{
    student s1, s2, s3;
    
    cout << "Enter details for student 1:\n";
    s1.get_all_data();
    
    cout << "Enter details for student 2:\n";
    s2.get_all_data();
    
    cout << "Enter details for student 3:\n";
    s3.get_all_data();

    student s4("vishal", "19GCIS101", "UDAIPUR");
    student s5("abhishek", "19EGICS105", "jaipur");

    cout << "Enter year and section for student 4:\n";
    s4.get_all_data(); 
    cout << "Enter year and section for student 5:\n";
    s5.get_all_data();

    student s6(s1);
    student s7(s4);

    cout << "\nRecords of the students are:";
    s1.print_record();
    s2.print_record();
    s3.print_record();
    s4.print_record();
    s5.print_record();
    s6.print_record();
    s7.print_record();

    return 0;
}
Editor is loading...
Leave a Comment