Pyq Part 1
Pyq Part 1
int main() {
int x = 10;
int *ptr = &x; // ptr points to the address of x
class ComplexNumber {
public:
int real, imag;
void display() {
std::cout << real << " + " << imag << "i" << std::endl;
}
};
int main() {
ComplexNumber c1(3, 4);
ComplexNumber c2 = -c1;
return 0;
}
class Student {
public:
std::string name;
int rollNumber;
float gpa;
// Default constructor
Student() {
name = "Unknown";
rollNumber = 0;
gpa = 0.0;
}
// Parameterized constructor
Student(std::string n, int r, float g) {
name = n;
rollNumber = r;
gpa = g;
}
// Copy constructor
Student(const Student &s) {
name = s.name;
rollNumber = s.rollNumber;
gpa = s.gpa;
}
// Destructor
~Student() {
std::cout << "Student object destroyed: " << name <<
std::endl;
}
int main() {
// ...
}
Note: This is just a basic implementation. You can add more member functions like display, set,
get, etc. to the Student class as needed.
Please let me know if you have any other questions or require further assistance.