Created
February 3, 2025 17:07
-
-
Save Fukushi-Chinmoku/ee860bfdaa30e9618a052f8bad171aed to your computer and use it in GitHub Desktop.
Student
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "Student.h" | |
int main() { | |
Student st1("Vadimka","12",4.3); | |
st1.print(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Student.h" | |
Student::Student() { | |
name = new char[1]; | |
name[0] = '\0'; | |
age = new char[1]; | |
age[0] = '\0'; | |
average_grade = 0; | |
} | |
Student::Student(char *name, char *age, double _average_grade) { | |
name = new char[strlen(name) + 1]; | |
strncpy(name, name, strlen(name)); | |
age = new char[strlen(age) + 1]; | |
strncpy(age, age, strlen(age)); | |
average_grade = _average_grade; | |
} | |
void Student::set_name(const char *_name) { | |
if (name != NULL) { | |
delete[] name; | |
} | |
name = new char[strlen(_name) + 1]; | |
strncpy(name, _name, strlen(_name)); | |
} | |
void Student::set_age(const char *_age) { | |
if (age != nullptr) { | |
delete[] age; | |
} | |
age = new char[strlen(_age) + 1]; | |
strncpy(age, _age, strlen(_age)); | |
} | |
void Student::set_average_grade(double _average_grade) { | |
average_grade = _average_grade; | |
} | |
const char * Student::get_name() { | |
return name; | |
} | |
const char * Student::get_age() { | |
return age; | |
} | |
double Student::get_average_grade() { | |
return average_grade; | |
} | |
bool Student::is_honors_student() { | |
return average_grade >= 4.5; | |
} | |
void Student::print() { | |
cout << "Name: " << name << endl; | |
cout << "Age: " << age << endl; | |
cout << "Average_grade: " << average_grade << endl; | |
cout << "is honors_student: " << is_honors_student() << endl; | |
} | |
Student::~Student() { | |
delete[] name; | |
delete[] age; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef STUDENT_H | |
#define STUDENT_H | |
#pragma once | |
#include <iostream> | |
using namespace std; | |
class Student { | |
private: | |
char* name; | |
char* age; | |
double average_grade; | |
public: | |
Student(); | |
Student(char* name, char* age, double average_grade); | |
void set_name(const char* _name); | |
void set_age(const char* _age); | |
void set_average_grade(double _average_grade); | |
const char* get_name(); | |
const char* get_age(); | |
double get_average_grade(); | |
bool is_honors_student(); | |
void print(); | |
~Student(); | |
}; | |
#endif //STUDENT_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment