Struct Student em C++

STRUCT BÁSICA:


#include <iostream>

using namespace std;

struct Student{
    string name;        //nome do estudante
    int rollNumber;     //numero de matricula
    float marks;        //nota do estudante
};

int main()
{
    Student studante1;
    studante1.name = "Gabriel";
    studante1.rollNumber = 12345;
    studante1.marks = 7.5;

    cout << "Nome do estudante      : " << studante1.name << "\n";
    cout << "Matricula do estudante : " << studante1.rollNumber << "\n";
    cout << "Nota do estudante      : " << studante1.marks << "\n";
    
    return 1;
}


STRUCT COM MÉTODOS:


#include <iostream>
#include <cstdlib>

using namespace std;

struct Student{
    string name;        //nome do estudante
    int rollNumber;     //numero de matricula
    float marks;        //nota do estudante

    void newStudent(string name){
        this-> name = name;
    }
    void setRollNumber(float rollNumber){
        this-> rollNumber = rollNumber;
    }
    void setMarks(float marks){
        this-> marks = marks;
    }
    string getName(){
        return name;
    }
    int getRollNumber(){
        return rollNumber;
    } 
    float getMarks(){
        return marks;
    }
};

int main(){
    Student studante1;
    studante1.newStudent("Gabriel");
    studante1.setRollNumber(12345);
    studante1.setMarks(7.5);

    cout << "Nome do estudante      : " << studante1.getName() << "\n";
    cout << "Matricula do estudante : " << studante1.getRollNumber() << "\n";
    cout << "Nota do estudante      : " << studante1.getMarks() << "\n";
    return 1;
}



Comentários

Postagens mais visitadas deste blog

Método da Interpolação por Eliminação Gaussiana em Scilab

Cálculo do Erro para Interpolação em Scilab

Método de Interpolação de Lagrange em Scilab