본문 바로가기
C++

[HackerRank] Classes and Objects - Easy

by 호아나트 2019. 10. 16.
반응형

https://www.hackerrank.com/challenges/classes-objects/problem

 

Classes and Objects | HackerRank

Familiarize yourself with classes and objects.

www.hackerrank.com

#include <cmath>

#include <cstdio>

#include <vector>

#include <iostream>

#include <algorithm>

#include <cassert>

using namespace std;



// Write your Student class here

class Student{

private:

int scores[5];

int sum;

public:

Student():sum(0)

{}



void input(){

for(int i=0;i<sizeof(scores)/sizeof(int);i++)

{

cin>>scores[i];

}

}



int calculateTotalScore()

{

for(int i=0;i<sizeof(scores)/sizeof(int);i++)

{

sum+=scores[i];

}

return sum;

}

};

반응형

'C++' 카테고리의 다른 글

[HackerRank] Inherited Code - Easy  (0) 2019.10.25
[HackerRank] Box it! - easy  (0) 2019.10.23
[HackerRank] Strings - Easy  (0) 2019.10.14
[HackerRank] StringStream - Easy  (0) 2019.10.14
[HackerRank]Attribute Parser - Medium  (0) 2019.10.14

댓글