Question

*** C++ *** Create a class called Student that contains a first name ( string) and...

*** C++ ***

Create a class called Student that contains a first name ( string) and an student id number (type long).
    1. Include a member function called get_data( ) to get data from the user for insertion into the object,
    2. Also include a function called display_data( ) that displays the student data.

Then write a complete program that uses the class to do some computation. Your main function, main( ), should create a Dynamic Array of type Student after inputting the number of students from the user and then input the data from the user. Once the data has been entered, give the user the following options
      a. Display database
      b. Display requested student record
      c. Delete a student record
      d. Modify a student record
Use appropriate constructors and destructors.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;

class Student{
   public:
       string name;
       long id;
       void get_data()
       {
           cout<<"Enter name : ";
           cin>>name;
           cout<<"Enter Id : ";
           cin>>id;
       }
      
       void display_data()
       {
           cout<<"Name : "<<name<<endl;
           cout<<"ID : "<<id<<endl;
       }
};

int main()
{
   Student *s;
   cout<<"Enter number of student : ";
   int n;
   cin>>n;
   s = new Student[n];
   for(int i=0;i<n;i++)
   {
       s[i].get_data();
   }
   system("cls");
   long temp;
   int i,j;
   Student *temp1;
   while(true)
   {
       cout<<"\n\na. Display database\nb. Display requested student record\nc. Delete a student record\nd. Modify a student record\ne. Exit\n";
       cout<<"Enter choice : ";
       char c;
       cin>>c;
       system("cls");
       switch (c)
       {
           case 'a':
               for( i=0;i<n;i++)
               {
                   s[i].display_data();
               }
               break;
           case 'b':
               cout<<"Enter Id to display data : ";
               cin>>temp;
               for( i=0;i<n;i++)
               {
                   if(s[i].id == temp)
                   {
                       s[i].display_data();
                       break;
                   }
               }
               break;
           case 'c':
               cout<<"Enter Id to display data : ";
               cin>>temp;
               for( i=0;i<n;i++)
               {
                   if(s[i].id == temp)
                   {
                       Student *temp1 = new Student[n-1];
                       int k =0;
                       for( j=0;j<n;j++)
                       {
                           if(i==j)
                           {
                               continue;
                           }
                           temp1[k]=s[j];
                           k++;
                       }
                       n = k;
                       s = new Student[n];
                       for( j=0;j<n;j++)
                       {
                           s[j]=temp1[j];
                       }
                       break;
                   }
               }
               break;
           case 'd':
               cout<<"Enter Id to modify data : ";
               cin>>temp;
               for( i=0;i<n;i++)
               {
                   if(s[i].id == temp)
                   {
                       s[i].get_data();
                       break;
                   }
               }
               break;
           case 'e':
               exit(0);
               break;
       }
   }
}

//Output

C:\Users\AdiShakti NavDurga\Desktop\student.exe Name : Shubham ID : 1001 Name : Sweta ID : 1002 Name : Renu ID : 1003 Name :

Add a comment
Know the answer?
Add Answer to:
*** C++ *** Create a class called Student that contains a first name ( string) and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class “Person” which includes first name, last name, age, gender, salary, and haveKids (Boolean)...

    Create a class “Person” which includes first name, last name, age, gender, salary, and haveKids (Boolean) variables. You have to create constructors and properties for the class. Create a “MatchingDemo” class. In the main function, the program reads the number of people in the database from a “PersonInfo.txt” file and creates a dynamic array of the object. It also reads the peoples information from “PersonInfo.txt” file and saves them into the array. In C# Give the user the ability to...

  • C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember...

    C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...

  • 12. Consider C++ class. Which one of the following choices is NOT correct? A. Class instances...

    12. Consider C++ class. Which one of the following choices is NOT correct? A. Class instances can be static, stack dynamic, or heap dynamic. B. If static or stack dynamic, they are referenced directly with value variables. C. If stack dynamic, they are referenced through pointers. D. Stack dynamic instances of classes are always created by the elaboration of an object declaration. E. The lifetime of such a class instance ends when the end of the scope of its declaration...

  • Visual C# Homework 2 You are to write a program which will create a class called...

    Visual C# Homework 2 You are to write a program which will create a class called Student Each student has a name age height and weight. These variables should be declared as private. Create the correct constructors and functions. In the main, you will create 5 students. Input the data for the 5 students from a file which already has information in it. Name the file “Information.txt”. After setting up all the data, it is time to sort based on...

  • Use C++ to create a class called Student, which represents the students of a university. A...

    Use C++ to create a class called Student, which represents the students of a university. A student is defined with the following attributes: id number (int), first name (string), last name (string), date of birth (string), address (string). and telephone (area code (int) and 7-digit telephone number(string). The member functions of the class Student must perform the following operations: Return the id numb Return the first name of the student Modify the first name of the student. . Return the...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • Programming: Create a class called City with two public variables: a string to store the name...

    Programming: Create a class called City with two public variables: a string to store the name of the city and a float to store the average temperature in Fahrenheit. Create one object of the class that you create and ask the user to enter the city name and the average temperature in Fahrenheit. Store these in the object of the class that you create. Then display the contents of the class. Once that is working, make the variables private and...

  • Define a class called Student with ID (string), name (string), units (int) and gpa (double). Define...

    Define a class called Student with ID (string), name (string), units (int) and gpa (double). Define a constructor with default values to initialize strings to NULL, unit to 0 and gpa to 0.0. Define a copy constructor to initialize class members to those of another Student passed to it as parameters. Overload the assignment operator (=) to assign one Student to another. Define a member function called read() for reading Student data from the user and a function called print()...

  • Hello. can anyone solve this. i am having hard time with this. please post a solution...

    Hello. can anyone solve this. i am having hard time with this. please post a solution ASAP a) Create a class named Student. Data fields for Student class include an integer Student ID, a String name, and a double CGPA. Methods include a constructor that requires values for all data fields, as well as get and set methods for each of the data fields. b) Create an application that allows a user to enter values for an array of 15...

  • List of Candles Create a class called CandleNode which has fields for the data (a Candle)...

    List of Candles Create a class called CandleNode which has fields for the data (a Candle) and next (CandleNode) instance variables. Include a one-argument constructor which takes a Candle as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures”.) public CandleNode (Candle c) { . . } The instance variables should have protected access. There will not be any get and set methods for the two instance variables. Create an abstract linked list class called CandleList. This...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT