Question
Asked Nov 24, 2019
125 views

Create a class of students that should contain fields like rollno,name,subject and marks?

check_circle

Expert Answer

Step 1

Programming language assumed is C++:

Class:

A C++ class is the building block, which contributes to the programming of objects. It is a user-defined data type that has its own data members and member functions that can be accessed and used by creating a class instance.

Consider a class of student. There may be many students belonging to different divisons and different schools but all of them will share some common properties like all of them will possess rollno, name, subjects, marks etc. So, student is the class and rollno, name, subjects, marks are its properties.

  • A Class is a data type specified by the user with data members and member functions.
  • Data members are the variables of data and members functions are used to control these variables.

Syntax of class definition is given below:

Class ClassName {

Access specifiers:

Date members;

Member function() {}

}

The keyword class is used to build the class ClassName. Access specifiers are used to set the accessibility of class members. Date members are the variables declared within class, they are also known as attributes. members functions are used to control these variables. At last class ends with semicolon(;).

 

 

Step 2

Below is the student class created:

class Student

{

            // Access specifier

            public:

 

            // Data Members

            int rollno;

            string name;

            string subject;

            float marks;

};

 

Step 3

Following is the c++ program to define a class student having some data member and member functions.

 

#include <iostream>

using namespace std;

class Student

{

            // Access modifiers

            public:

 

            // Data Members

            int rollno;

            string name;

            string subject;

            float marks;

           

            // Member Functions()

            void print()

            {

            cout << "Student roll number is: " << rollno << endl;

            cout << "Student name is: " << name << endl;

            cout << "Student subject is: " << subject << endl;

...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in
EngineeringComputer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Submission Instructions Follow the instructions for How to Submit Programming Assignments. Assignmen...

A: the name of the java application is PatternMaker.A string variable firstString is used to store the ...

question_answer

Q: I need help with this in python. I'm not understanding it

A: To solve this Question following variables and functions have been used:Variables: Arce, landsz, tot...

question_answer

Q: Write Python programs to solve the problem. Shipping is free for online orders totaling $50 or more ...

A: Python program that prompts for the unit price of an item and its quantity#get the inputs from the u...

question_answer

Q: List and describe four vulnerability intelligence sources. Which seems the most effective? Why?

A: Sources of Vulnerability IntelligenceSecurity VendorsSoftware VendorsGovernment and public organizat...

question_answer

Q: d. Explain the steps of the fetch-decode-execute cycle. Your explanation should include what is happ...

A: Fetch-decode-execute cycle stepsFetch-decode-execute instruction cycle consists of three phases. The...

question_answer

Q: Your uncle has given you a new monitor for your computer. When you attempt to connect it, you notice...

A: Basically, there are two types of displays: LED and LCD displays. Such displays are very similar and...

question_answer

Q: Define a splitstream upgrade, patch, release and version as they relate to system maintenance?

A: System maintenanceSystem maintenance is used for achieving user and organization goals. it includes ...

question_answer

Q: The prompt asks: Write a function that calculates the amount of money a person would earn over a per...

A: Program Approach-1)Define function named totalEarned () with years as a parameter.2)Declare and init...

question_answer

Q: To increase security of data stored on an RODC, what can be configured to specify domain objects tha...

A: Windows Server 2008 produces a new kind of domain controller, RODC (Read-only domain controller). Th...