-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.cpp
More file actions
71 lines (58 loc) · 1.96 KB
/
student.cpp
File metadata and controls
71 lines (58 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
*This file implements the structure declared in student.h
*Please include the said header and then either use this implementation
*or create a different one yourself (or feel free to modify this one.)
*/
/*
*********************Things to include in documentation***************************
*
*************************************END******************************************
*/
/*
********************************Possible Errors***********************************
*Use the following compilation command:
* g++ -c -o student.o student.cpp -std=c++14
*Or else use the provided make file to build the entire project
************************************END********************************************
*/
#include "student.h"
#include <string>
#include <iostream>
using namespace std;
//This let's the structure be used in cout.
ostream& operator<< (ostream &os,Students &stu){
os << "Roll number: " << stu.rollNo
<< "\nName: " << stu.name
<< "\nMarks: " << stu.marks;
return os;
}
//This let's the structure be used in cin
istream& operator >> (istream &in, Students &input){
cout << "\nEnter Roll No: ";
in >> input.rollNo;
in.clear();
in.ignore (1000, '\n');
cout << "Enter Name: ";
getline (in, input.name);
cout << "Enter Marks: ";
in >> input.marks;
return in;
}
//Checks equality for two objects of structure student
bool Students::operator== (Students check) const{
return (check.rollNo == this->rollNo);
}
Students::Students (){} //Ensures that you can still create an object without giving the required parameters.
Students::Students (const Students &cpy){ //Copy constructor to copy
//Copies all data to the new object
rollNo = cpy.rollNo;
name = cpy.name; //Copies the name
marks = cpy.marks;
}
//Initializes the object with the provided data
Students::Students (int RollNo, string Name, double Marks){
rollNo = RollNo;
name = Name;
marks = Marks;
}
Students::~Students (){} //There is no dynamic memory that needs to be taken care of