Answers for "class functions"

C++
5

c++ class method example

class Object {
public:
	int var;
	void setVar(int n) {
		var = n;
	}
	int getNum() {
		return var;
	}
};

int main() {
	Object obj;
	obj.setVar(13);
	std::cout << obj.getNum() << std::endl;
	return 0;
}
Posted by: Guest on January-18-2020
-1

Using functions in Class

class Student{
    int scores[5];
    public:
    void input(){
        for(int i=0; i<5; i++){
            cin >> scores[i];
        }
    }
    int calculateTotalScore(){
        int total = 0;
        for(int i=0; i<5; i++){
            total += scores[i];
        }
        return total;
    }
};
Posted by: Guest on May-16-2021

Code answers related to "class functions"

Browse Popular Code Answers by Language