Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Assignment: (Do this in C++.) (Please show me the whole answer.Thanks.) Crea

ID: 666422 • Letter: C

Question

C++ Assignment: (Do this in C++.)

(Please show me the whole answer.Thanks.)

Create an application to manipulate an array of student record objects. A student record will consist of a name (first, middle, and last), an ID number (9 numeric digits, cannot be more or less), an address (street, city, state, and 5 digit Zip code), and a phone number (3 digit area code and 7 digit number). The application will support an array of students. The user will be allowed to enter records from the keyboard, sort records by either name (last, first, middle) or by ID, save the records to a disk file (name supplied by user), and read the records from a disk file (name again supplied by user).

Create a fixed length string that must check that the length of the string is the required length. The fixed length class should be done as a template with the number of characters as the template argument. From this fixed length string, derive a class to hold digits of a fixed length.

Create component classes as necessary to use together to implement the student record class.

Use either the array template created in an earlier lab to handle the array or you may use the vector class from the STL to handle the array of student record objects.

The maximum number of students will be 25 (it may be less).

Explanation / Answer

Here is the solution :

First approach :

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
struct student
{
    char *name;
    int rn;
    float age;
};
void main()
{
    struct student *s,*s1;
    clrscr();
    int n;
    void read(student *,int);
    void display(student *,int);
    cout<<"enter the number of student ";
    cin>>n;
    s=s1;
    read(s,n);
    s=s1;
    display(s,n);
    getch();
}
void read(student *t,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        cout<<" enter the student "<<i+1<<" record ";
        gets((t+i)->name);
        //s->name=nam;
        //cin>>(t+i)->name;
        cin>>(t+i)->rn;
        cin>>(t+i)->age;
    }
}
void display(student *s,int n)
{
    int i;
    //cout<<"enter the number of student ";
    //cin>>n;
    for(i=0;i<n;i++)
    {
        cout<<" the student "<<i+1<<" record ";
        cout<<"name of student ";
        puts((s+i)->name);
        //cout<<(s+i)->name;
        cout<<" roll number "<<(s+i)->rn;
        cout<<" age "<<(s+i)->age;
        cout<<" ";
    }
}

Another or second approach :

#include<iostream.h>
#include<conio.h>
class stud_info
{
    private:
    char *name;
    int rn;
    char s[8];
    public:
    void getdata();
    void display();
    class date
    {
        private:
        int mm,dd,yy;
        public:
        void getdata();
        void display();
        class t_age
        {
            private:
            float age;
            public:
            void getdata();
            void display();
        };
    };
};
void stud_info::getdata()
{
    cout<<"enter the student name,sex,roll number ";
    cin>>name;
    cin>>s;
    cin>>rn;

}
void stud_info::display()
{
    cout<<" student record is "<<name <<" sex "<<s <<" roll number "<<rn;
}
void stud_info::date::getdata()
{
    cout<<" enter the date of birth in dd mm yy format ";
    cin>>dd>>mm>>yy;
}
void stud_info::date::display()
{
    cout<<" the date of birth is "<<dd<<" "<<mm<<" "<<yy;
}
void stud_info::date::t_age::getdata()
{
    cout<<" enter the age ";
    cin>>age;
}
void stud_info::date::t_age::display()
{
    cout<<" the age of student "<<age;
}
void main()
{
    clrscr();
    class stud_info s;
    class stud_info::date d;
    class stud_info::date::t_age a;
    s.getdata();
    d.getdata();
    a.getdata();
    s.display();
    d.display();
    a.display();
    getch();
}