1. Create a class named 'Student' with a string variable 'name' , an integer variable 'roll_no' , 3 float variable called marks 1 , marks 2 , marks 3 and a character variable called grade . Assign the value by creating an object of the class Student.
Then print the ouput like:
Name: hamza manzoor
Roll No: s2019266036
Marks 1: 63.5
Marks 2: 55.5
Marks 3: 89.5
Grade: B
#include <iostream>
using namespace std;
class Student
{
const char* name;
int roll_no;
float marks1;
float marks2;
float marks3;
char grade;
public:
Student(const char* name, int roll_no, float marks1, float marks2, float marks3, char grade)
{
this->name = name;
this->roll_no = roll_no;
this->marks1 = marks1;
this->marks2 = marks2;
this->marks3 = marks3;
this->grade = grade;
}
void print()
{
cout << "Name: " << name << endl;
cout << "Roll No: " << roll_no << endl;
cout << "Marks 1: " << marks1 << endl;
cout << "Marks 2: " << marks2 << endl;
cout << "Marks 3: " << marks3 << endl;
cout << "Grade: " << grade << endl;
}
};
int main()
{
Student student("hamza manzoor", 2019266036, 63.5, 55.5, 89.5, 'B');
student.print();
return 0;
}
Comments
Leave a comment