PHC - Baal
Eternal Poster
- Joined
- Jun 16, 2017
- Posts
- 693
- Reaction
- 231
- Points
- 291
DELETED
Last edited:
yes po, makakatulong po yunAy ilagay mo na lang sa loob ng function yung code. Hindi na kasi ako nag-c-C++. C# na gamit ko. Wala akong setup na dev environment for C++.
Kailangan mo ba yung buong code including pagkuha ng inputs?
#include <iostream>
using namespace std;
// Intializing the Compute class
class Compute {
//Declaring an array to store the input of user as private.
private:
int x[3];
//Initializing the 2D array containing the points from the rubrics.
double points[3][4] = { {7.5, 15, 22.5, 30},
{7.5, 15, 22.5, 30},
{10, 20, 30, 40} };
//Constructor for the Compute class and public as the modifier.
public:
Compute(int n1, int n2, int n3){
// Taking the user's input and storing it in an array.
x[0] = n1;
x[1] = n2;
x[2] = n3;
}
public:
//Method to get total points base on the user's input and public as the modifier.
float getPoints(){
double sum = 0; // Initialize the sum
for(int i = 0; i < 3; i++){ // Assigning i as row
sum += points[i][x[i] - 1]; //Choice of user as column
}
return sum; // Return the sum
}
};
int main(void) {
//Declaring the Objects that are given in the expected output.
Compute obj1 = Compute(4, 4, 4); //expected data's for object 1
Compute obj2 = Compute(1, 2, 3); //expected data's for object 2
cout<<"Object 1"<<endl<<obj1.getPoints()<<" points"<<endl; //expected output for object 1
cout<<"Object 2"<<endl<<obj2.getPoints()<<" points"<<endl; //expected output for object 2
//Declaring the variables for the user's input.
int n1, n2, n3;
cout<<"Obect 3"<<endl;
//Taking the input from user.
cout<<"Input: "; cin>>n1>>n2>>n3;
// Then passing the inputs of user as arguments in the Compute class.
Compute obj3 = Compute(n1, n2, n3);
//Then finally print the total points base on the user input.
cout<<"Object 3"<<endl<<obj3.getPoints()<<" points"<<endl;
}