What's new

Help DELETED THREAD

Status
Not open for further replies.
Multi-dimensional array and indexing lang yan.

Example:

double[3][4] perd = [[30, 22.5, 15, 7.5], [30, 22.5, 15, 7.5], [40, 30, 20, 10]];

double input1Value = perd[0][input1-1];
double input2Value = perd[1][input2-1];
double input3Value = perd[2][input3-1];

double result = input1Value + input2Value + input3Value;


So take care lang sa indexing since arrays are 0-based.
 
Ay 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?
 
Eto ts, applying the OOP of c++, madali lang naman ts, 2D array lang at class ang gagawin.
1622269586731.png
 

Attachments

Ayan na sir sa taas yung logic para ma-compute yung points.

Need mo lang ilagay sa function and add the logic to get the inputs.
 
Ay 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?
yes po, makakatulong po yun :D
 
Complete c++ code including the comments mentioned in the problem statement.
C++:
#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;
}
1622273599578.png

Kung gusto nyo pong mag donate ts, tumatanggap po ako hehe.
 

Attachments

salamat po sa mga comments, talagang hirap ako sa programming ngayon eh 😅 di bale pag nakaluwag luwag papatakan ko po kayo
 
Status
Not open for further replies.

Similar threads

Back
Top