What's new

Closed Need help optimizing your program code? pasok!

Status
Not open for further replies.
Baka makakuha ka ng idea. Yan nalang maibibgay kong tulong sayo.
Code:
#include <iostream>
#include <stdlib.h>     /* srand, rand */
#include <time.h>

using namespace std;

int main()
{
    srand (time(NULL));
    
    string easyQuestions[15] =
    {
        "Question 01",
        "Question 02",
        "Question 03",
        "Question 04",
        "Question 05",
        "Question 06",
        "Question 07",
        "Question 08",
        "Question 09",
        "Question 10",
        "Question 11",
        "Question 12",
        "Question 13",
        "Question 14",
        "Question 15",
    };
    
    int randomNumber;
    int shownQuestion[5] = {-1, -1, -1, -1, -1};
    bool shown = false;
    int totalQuestion = 0;
    
    while(totalQuestion < 5)
    {
        randomNumber = rand() % 15;
         //Check if shown
        for(int j = 0; j < 5; j++)
        {
            if(shownQuestion[j] == randomNumber)
            {
                shown = true;
                break;
            }
        }
        if(!shown)
        {
            //Show Question now
            cout<< easyQuestions[randomNumber] << endl;
            shownQuestion[totalQuestion] = randomNumber;
            totalQuestion++;
        }
        
        shown = false;
    }
      
    return 0;
}
 
Sir bale ano gagamitin dyan array gusto ko kasi itry sa java.
Who wants to be a millionaire yan. Gawin mo nga daw.
two dimensional array. Questions with its choices and answer.
Tapos bale 4 na 2D array. Easy, Medium, Hard, Tapos identification.
Pag may progress ka . Pakita mo. :)
 
Who wants to be a millionaire yan. Gawin mo nga daw.
two dimensional array. Questions with its choices and answer.
Tapos bale 4 na 2D array. Easy, Medium, Hard, Tapos identification.
Pag may progress ka . Pakita mo. :)
Sige sir try ko po k
Who wants to be a millionaire yan. Gawin mo nga daw.
two dimensional array. Questions with its choices and answer.
Tapos bale 4 na 2D array. Easy, Medium, Hard, Tapos identification.
Pag may progress ka . Pakita mo. :)
sir bale ganito po dapat yung pag approch neto array saka set and hashset?
 
Baka makakuha ka ng idea. Yan nalang maibibgay kong tulong sayo.
Code:
#include <iostream>
#include <stdlib.h>     /* srand, rand */
#include <time.h>

using namespace std;

int main()
{
    srand (time(NULL));
   
    string easyQuestions[15] =
    {
        "Question 01",
        "Question 02",
        "Question 03",
        "Question 04",
        "Question 05",
        "Question 06",
        "Question 07",
        "Question 08",
        "Question 09",
        "Question 10",
        "Question 11",
        "Question 12",
        "Question 13",
        "Question 14",
        "Question 15",
    };
   
    int randomNumber;
    int shownQuestion[5] = {-1, -1, -1, -1, -1};
    bool shown = false;
    int totalQuestion = 0;
   
    while(totalQuestion < 5)
    {
        randomNumber = rand() % 15;
         //Check if shown
        for(int j = 0; j < 5; j++)
        {
            if(shownQuestion[j] == randomNumber)
            {
                shown = true;
                break;
            }
        }
        if(!shown)
        {
            //Show Question now
            cout<< easyQuestions[randomNumber] << endl;
            shownQuestion[totalQuestion] = randomNumber;
            totalQuestion++;
        }
       
        shown = false;
    }
     
    return 0;
}
Sir tinry ko po to sa java pero bakit nag outofbound po sya saka ano po ibig sabihin neto int shownQuestion [5] = {-1, -1, -1, -1, -1}


public class WhoWantsToBeAmillionaire
{
static Random random = new Random();
static int randomNumber;
static int shownQuestion [] = {-1, -1, -1, -1, -1};
static boolean shown = false;
static int totalQuestion = 0;

static String easyQuestions [] =

{
"Question 01",
"Question 02",
"Question 03",
"Question 04",
"Question 05",
"Question 06",
"Question 07",
"Question 08",
"Question 09",
"Question 10",
"Question 11",
"Question 12",
"Question 13",
"Question 14",
"Question 15",
};


public static void main (String [] args){

Question();
}

static void Question(){

while(totalQuestion < 5)
{
randomNumber = random.nextInt() % 15;
//Check if shown
for(int i = 0; i < 5; i++)
{
if(shownQuestion == randomNumber)
{
shown = true;
break;
}
}
if(!shown)
{
//Show Question now
System.out.println(easyQuestions[randomNumber] );
shownQuestion[totalQuestion] = randomNumber;
totalQuestion++;
}

shown = false;
}

return;
}
}
 
Who wants to be a millionaire yan. Gawin mo nga daw.
two dimensional array. Questions with its choices and answer.
Tapos bale 4 na 2D array. Easy, Medium, Hard, Tapos identification.
Pag may progress ka . Pakita mo. :)
Sir My Ginawa po ako Ganito po Mag Random Na Array Hanggang 6 Lang Po Yung ma Rarandom Na Mga Question Hindi ko po Alam kung Tama tong pinag gagawa ko.


public class SinoGustoMagingMayaman
{
static final int MAX_NUMBERS = 5;
static final int NUMBER_OF_RANDOM = 15;
static String easyQuestions [] =

{
"Question 01",
"Question 02",
"Question 03",
"Question 04",
"Question 05",
"Question 06",
"Question 07",
"Question 08",
"Question 09",
"Question 10",
"Question 11",
"Question 12",
"Question 13",
"Question 14",
"Question 15",
};

public static void main (String [] args){

randomNumbersUpTo15();

}
static void randomNumbersUpTo15(){

Random random = new Random();
int generateNumbers = 0;
for(int i = 0; i<MAX_NUMBERS; i++){
generateNumbers = random.nextInt(easyQuestions.length);
System.out.println(easyQuestions[generateNumbers]);
}
}
}
 
Sir My Ginawa po ako Ganito po Mag Random Na Array Hanggang 6 Lang Po Yung ma Rarandom Na Mga Question Hindi ko po Alam kung Tama tong pinag gagawa ko.


public class SinoGustoMagingMayaman
{
static final int MAX_NUMBERS = 5;
static final int NUMBER_OF_RANDOM = 15;
static String easyQuestions [] =

{
"Question 01",
"Question 02",
"Question 03",
"Question 04",
"Question 05",
"Question 06",
"Question 07",
"Question 08",
"Question 09",
"Question 10",
"Question 11",
"Question 12",
"Question 13",
"Question 14",
"Question 15",
};

public static void main (String [] args){

randomNumbersUpTo15();

}
static void randomNumbersUpTo15(){

Random random = new Random();
int generateNumbers = 0;
for(int i = 0; i<MAX_NUMBERS; i++){
generateNumbers = random.nextInt(easyQuestions.length);
System.out.println(easyQuestions[generateNumbers]);
}
}
}
Pasensya na hindi ko eenternain-in yang reply mo hanggang wala sa code tag yang program mo. Ilang beses ko na sinasabi sayo.
 
Pasensya na sir ha hindi ko po kasi alam kung pano ganito po ba tapus yung code #program code

Pasensya na hindi ko eenternain-in yang reply mo hanggang wala sa code tag yang program mo. Ilang beses ko na sinasabi sayo.
Code:
public class SinoGustoMagingMayaman
{
    static final int MAX_NUMBERS = 5;
    static final int NUMBER_OF_RANDOM = 15;
    static String easyQuestions [] = 

    {
        "Question 01",
        "Question 02",
        "Question 03",
        "Question 04",
        "Question 05",
        "Question 06",
        "Question 07",
        "Question 08",
        "Question 09",
        "Question 10",
        "Question 11",
        "Question 12",
        "Question 13",
        "Question 14",
        "Question 15",
    };
   
    public static void main (String [] args){
       
        randomNumbersUpTo15();
       
    }
        static void randomNumbersUpTo15(){
           
        Random random = new Random();
        int generateNumbers = 0;
        for(int i = 0; i<MAX_NUMBERS; i++){
            generateNumbers = random.nextInt(easyQuestions.length);
            System.out.println(easyQuestions[generateNumbers]);
        }
    }
}

Sir sorry po hindi ko po kasi alam nung una kaya hindi ko po nalalagay sa code tag. Bale sir my ginawa po ako ganito po mag rarandom sya ng 6 na question.
 
Code:
public class SinoGustoMagingMayaman
{
    static final int MAX_NUMBERS = 5;
    static final int NUMBER_OF_RANDOM = 15;
    static String easyQuestions [] =

    {
        "Question 01",
        "Question 02",
        "Question 03",
        "Question 04",
        "Question 05",
        "Question 06",
        "Question 07",
        "Question 08",
        "Question 09",
        "Question 10",
        "Question 11",
        "Question 12",
        "Question 13",
        "Question 14",
        "Question 15",
    };
  
    public static void main (String [] args){
      
        randomNumbersUpTo15();
      
    }
        static void randomNumbersUpTo15(){
          
        Random random = new Random();
        int generateNumbers = 0;
        for(int i = 0; i<MAX_NUMBERS; i++){
            generateNumbers = random.nextInt(easyQuestions.length);
            System.out.println(easyQuestions[generateNumbers]);
        }
    }
}

Sir sorry po hindi ko po kasi alam nung una kaya hindi ko po nalalagay sa code tag. Bale sir my ginawa po ako ganito po mag rarandom sya ng 6 na question.
Okay so ang problema dyan may possibility na maulit ang question.
Dapat hindi maulit yun.
Dapat gawa ka ng array tapos lagay mo dun yung index ng question.
tapos sa loop icheck mo kung nashow na yung question na yun by comparing sa index ng question.
 
Okay so ang problema dyan may possibility na maulit ang question.
Dapat hindi maulit yun.
Dapat gawa ka ng array tapos lagay mo dun yung index ng question.
tapos sa loop icheck mo kung nashow na yung question na yun by comparing sa index ng question.
Code:
public class SinoGustoMagingMayaman
{
    static final int MAX_NUMBERS = 5;
    static final int NUMBER_OF_RANDOM = 15;
    static ArrayList<String> question;
    static String easyQuestions [] = 

    {
        "Question 01",
        "Question 02",
        "Question 03",
        "Question 04",
        "Question 05",
        "Question 06",
        "Question 07",
        "Question 08",
        "Question 09",
        "Question 10",
        "Question 11",
        "Question 12",
        "Question 13",
        "Question 14",
        "Question 15",
    };
   
    public static void main (String [] args){
       
        randomQuestionUpTo15();
       
    }
        static void randomQuestionUpTo15(){
        question = new ArrayList<String>();
        Random random = new Random();
        int generateNumbers = 0;
        boolean duplicate = false;
        for(int i = 0; i<MAX_NUMBERS; i++){
        do{
            generateNumbers = random.nextInt(easyQuestions.length);
            if(question.contains(easyQuestions[generateNumbers])){
                duplicate = true;
            }else{
                question.add(easyQuestions[generateNumbers]);
                duplicate = false;
            }
        }while(generateNumbers == 0 || duplicate);
        System.out.println(easyQuestions[generateNumbers] + "\t");
        }
    }
}

Sir bale ganito po yung ganiwa ko ulet para lang hindi ma duplicate yung tanong tama po ba?
 
Code:
public class SinoGustoMagingMayaman
{
    static final int MAX_NUMBERS = 5;
    static final int NUMBER_OF_RANDOM = 15;
    static ArrayList<String> question;
    static String easyQuestions [] =

    {
        "Question 01",
        "Question 02",
        "Question 03",
        "Question 04",
        "Question 05",
        "Question 06",
        "Question 07",
        "Question 08",
        "Question 09",
        "Question 10",
        "Question 11",
        "Question 12",
        "Question 13",
        "Question 14",
        "Question 15",
    };
  
    public static void main (String [] args){
      
        randomQuestionUpTo15();
      
    }
        static void randomQuestionUpTo15(){
        question = new ArrayList<String>();
        Random random = new Random();
        int generateNumbers = 0;
        boolean duplicate = false;
        for(int i = 0; i<MAX_NUMBERS; i++){
        do{
            generateNumbers = random.nextInt(easyQuestions.length);
            if(question.contains(easyQuestions[generateNumbers])){
                duplicate = true;
            }else{
                question.add(easyQuestions[generateNumbers]);
                duplicate = false;
            }
        }while(generateNumbers == 0 || duplicate);
        System.out.println(easyQuestions[generateNumbers] + "\t");
        }
    }
}

Sir bale ganito po yung ganiwa ko ulet para lang hindi ma duplicate yung tanong tama po ba?
Vast na pala knowledge mo sa java. :) Okay na yan.
Pero hindi pa yan yung buong program eh. Tapusin mo sa spare time mo.
 
Vast na pala knowledge mo sa java. :) Okay na yan.
Pero hindi pa yan yung buong program eh. Tapusin mo sa spare time mo.
Sir anong Vast? Saka anong po next step dito kahit guide lang po gusto ko po kasi talaga my ginagawa program para lang po matuto ako tulad nyo po, gusto ko balang araw makapag tuturo din ako sa iba.
 
Sir anong Vast? Saka anong po next step dito kahit guide lang po gusto ko po kasi talaga my ginagawa program para lang po matuto ako tulad nyo po, gusto ko balang araw makapag tuturo din ako sa iba.
Vast english ng malawak.
Ang next step dyan. Yung array ng question gawin mong 2D tapos instead na question lang ang laman, meron ding 4 choices tapos 1 answer para sa checking.
Tapos interact with the user. Show the question and choices tapos kuha ka input ng answer tapos gawa ka ng function to check the answer. or if else lang.
 
Vast english ng malawak.
Ang next step dyan. Yung array ng question gawin mong 2D tapos instead na question lang ang laman, meron ding 4 choices tapos 1 answer para sa checking.
Tapos interact with the user. Show the question and choices tapos kuha ka input ng answer tapos gawa ka ng function to check the answer. or if else lang.
Ah bale sir gagawin kong 2D array to tapus sa loob ng question my mga pag pipilian tapus gagamitan ko nlng ng Scanner para sa input and then para sa tama sagot if else po.
 
Ah bale sir gagawin kong 2D array to tapus sa loob ng question my mga pag pipilian tapus gagamitan ko nlng ng Scanner para sa input and then para sa tama sagot if else po.
Yeah. Yung tulad sa movie array sa last program.
 
Aba. Ikaw yung dati. Hahaha!

Tulungan kita paunti unti.
Binigay ko sayo yung array. Hindi mo ata binasa.
Simula tayo sa easy questions. Gawin mo na!
Declare ka ng array variable ng easy question.
Pero wag kang mahiya kung hindi mo alam. sabihin mo.
Sir pwede maka hingi ng ng array na babasahin medyo naguguluhan ako kasi ako.
 
Status
Not open for further replies.
Back
Top