This forum is in archive mode. You will not be able to post new content.

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - haseebr21

Pages: [1] 2
1
C - C++ / Re: Stuck at Merge Sort Problem
« on: September 22, 2015, 08:02:23 AM »
I am assuming you have ran the code? Assuming that.....are you getting any errors? (If so what are they)

EDIT: undeclared identifiers...maybe?

I think there is some logical error which outputs a wrong value.

2
C - C++ / Stuck at Merge Sort Problem
« on: September 21, 2015, 08:51:54 PM »
Hello, I am actually doing a merge sort assignment and I am stuck at the code and I don't know where am I making error, kindly help me out.

Code: [Select]
/**
  * Divide  : Divide the n-element array into two n/2-element
  *           sub-arrays
  * Conquer : Sort the two sub-arrays recursively using
  *           merge sort
  * Combine : Merge the two sorted subsequences to form the
  *           sorted array
  **/

#include<stdio.h>

int arr[20];       // array to be sorted

int main()
{

  int n,i;
  clrscr();
  printf("Enter the size of array\n");  // input the elements
  scanf("%d",&n);
  printf("Enter the elements:");
  for(i=0; i<n; i++)
    scanf("%d",&arr[i]);

  merge_sort(arr,0,n-1);  // sort the array

  printf("Sorted array:");  // print sorted array
  for(i=0; i<n; i++)
    printf("%d",arr[i]);
   getch();
  return 0;
}

int merge_sort(int arr[],int low,int high)
{
  int mid; int i;
  if(low<high) {

    mid=(low+high)/2;
    // Divide and Conquer
    merge_sort(arr,low,mid);
    merge_sort(arr,mid+1,high);
    // Combine


    merge(arr,low,mid,high);
  }

  return 0;
}

int merge(int arr[],int l,int m,int h)
{
  int arr1[10],arr2[10];  // Two temporary arrays to
  //hold the two arrays to be merged
  int n1,n2,i,j,k,z;

i=0;j=0;

for(z=l;z<=m;z++)
{
arr1[i]=arr[z];
i++;
}
for(z=m+1;z<=h;z++)
{
arr2[j]=arr[z];
j++;
}




  n1=i;
  n2=j;
  i=0;
  j=0;
  for(k=l; k<=h; k++)
  { //process of combining two sorted arrays

    if(i<n1 && j<n2)
    {
if(arr1[i]<=arr2[j])
      arr[k]=arr1[i++];
else
     arr[k]=arr2[j++];
     }
     else if(i>=n1)
     {
  arr[k]=arr[j++];
     }
     else
     {
arr[k]=arr[i++];
     }


  }

  return 0;
}


3
Java / Music Player in Java Gui[UPDATED]
« on: June 07, 2015, 06:34:32 PM »
Hello, actually I was making a music player in java that would be able to play .mp3 and .wav music files. I am currently stuck at the code that will make it play song and I can' seem to figure out why it is not playing a .wav file. If anyone could help me to solve it. Here is My code
Code: [Select]

package project_final;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.applet.*;
import sun.audio.AudioStream;
import sun.audio.*;
import java.io.*;
import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.applet.AudioClip;
       
/**
 *
 * @author Haseeb Raja
 */
public class lookAndFeel extends JFrame {
    private JLabel label1;
    private JPanel panel_slider;
    private JPanel panel_buttons;
    private JPanel panel_header;
    private JButton play_pause_Button;
    private JButton stop_Button;
    private JButton loop_Button;
    private JButton like_Button;
    private JButton browse_Button;
    private JFrame frame1;
    private JSlider slider;
    private ButtonGroup buttongroup;
    JFileChooser fileChooser ;
    private String audioFilePath;
   private String lastOpenPath;
        private AudioClip currentsound;
        private AudioClip sound1;
   
    lookAndFeel() {
        super("Hafazaeeb Music Player");
        frame1=new JFrame();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(450, 150);
        setAlwaysOnTop(true);
        setResizable(false);
       
        setLayout(new FlowLayout());
       
        panel_slider = new JPanel();
        panel_buttons = new JPanel();
        panel_slider.setSize(50,50);
        panel_buttons.setSize(50,50);
       
        Icon pause = new ImageIcon(getClass().getResource("Pause.png"));
        play_pause_Button= new JButton("Pause",pause);
        play_pause_Button.setEnabled(false);
        panel_buttons.add(play_pause_Button);
       
        Icon stop = new ImageIcon(getClass().getResource("stop.gif"));
        stop_Button = new JButton("Stop",stop);
        stop_Button.setEnabled(false);
        panel_buttons.add(stop_Button);
       
        Icon like = new ImageIcon(getClass().getResource("like.png"));
        like_Button = new JButton("Like",like);
        panel_buttons.add(like_Button);
       
        Icon loop = new ImageIcon(getClass().getResource("loop.gif"));
        loop_Button = new JButton("Repeat",loop);
        loop_Button.setEnabled(false);
        panel_buttons.add(loop_Button);
       
        JFileChooser fc= new JFileChooser();
        Icon open = new ImageIcon(getClass().getResource("Open.png"));
        browse_Button= new JButton("Open",open);
        panel_slider.add(browse_Button);
       
        slider = new JSlider();
        panel_slider.add(slider);
       
        panel_slider.setVisible(true);
        panel_buttons.setVisible(true);
       
        add(panel_slider);
        add(panel_buttons);
       
       
       
       
        handlerClass handler = new handlerClass();
        stop_Button.addActionListener(handler);
        loop_Button.addActionListener(handler);
        browse_Button.addActionListener(handler);
        play_pause_Button.addActionListener(handler);       
       
   
        frame1.pack();
        setVisible(true);
    }
      public void stop()
    {
         currentsound.stop(); // stop AudioClip
      } //


    private class handlerClass implements ActionListener{
       
 public void actionPerformed( ActionEvent actionEvent )
            {
              if(actionEvent.getSource()== browse_Button) {
                  fileChooser = new JFileChooser();
                           
      FileFilter wavFilter = new FileFilter() {
         @Override
         public String getDescription() {
            return "Sound file (*.WAV)";
         }


         @Override
         public boolean accept(File file) {
            if (file.isDirectory()) {
               return true;
            } else {
               return file.getName().toLowerCase().endsWith(".wav");
            }
         }
      };


     
      fileChooser.setFileFilter(wavFilter);
      fileChooser.setDialogTitle("Open Audio File");
      fileChooser.setAcceptAllFileFilterUsed(false);


      int userChoice = fileChooser.showOpenDialog(browse_Button);
      if (userChoice == JFileChooser.APPROVE_OPTION) {
         audioFilePath = fileChooser.getSelectedFile().getAbsolutePath();
         lastOpenPath = fileChooser.getSelectedFile().getParent();
                         play_pause_Button.setEnabled(true);
                            loop_Button.setEnabled(true);       
                            stop_Button.setEnabled(true);   
         
              }
              else if( actionEvent.getSource() == play_pause_Button )
                 currentsound.play();
             else if ( actionEvent.getSource() == loop_Button )
                currentsound.loop(); // play AudioClip continuously
              else if ( actionEvent.getSource() == stop_Button )
                currentsound.stop(); // stop AudioClip
              } // end method actionPerformed
            } // end class ButtonHandler
         } // end class LoadA
}
   

[UPDATE] loop working,pause and play working (applied on mp3 via downloading javazoom llib), pause still not working though I've got a clue, will upload the completed code as soon as I will complete.
I made the mp3 player though, here is the code:

Code: [Select]

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package project_final;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.*;
import javazoom.jl.player.Player;


/**
 *
 * @author Haseeb Raja
 */
public class lookAndFeel extends JFrame {
    private JLabel label1;
    private JPanel panel_slider;
    private JPanel panel_buttons;
    private JPanel panel_header;
    private JButton play_Button;
    private JButton pause_Button;
    private JButton stop_Button;
    private JButton loop_Button;
    private JButton like_Button;
    private JButton browse_Button;
    private JFrame frame1;
    private JSlider slider;
    private ButtonGroup buttongroup;
    JFileChooser fileChooser ;
    Player player; // object that can actually play, pause, etc a song
    File file; // object that manipulates files
    FileInputStream fis;
    BufferedInputStream bis;
    Thread Thread=new Thread();
   

    lookAndFeel() {
        super("Hafazaeeb Music Player");
        frame1=new JFrame();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(480, 150);
        setAlwaysOnTop(true);
        setResizable(false);
       
        setLayout(new FlowLayout());
       
        panel_slider = new JPanel();
        panel_buttons = new JPanel();
        panel_slider.setSize(50,50);
        panel_buttons.setSize(50,50);
       
        Icon pause = new ImageIcon(getClass().getResource("pause.png"));
        pause_Button= new JButton("pause",pause);
        pause_Button.setEnabled(false);
        panel_buttons.add(pause_Button);
       
        Icon play = new ImageIcon(getClass().getResource("Play.gif"));
        play_Button= new JButton("Play",play);
        play_Button.setEnabled(false);
        panel_buttons.add(play_Button);
       
        Icon stop = new ImageIcon(getClass().getResource("stop.gif"));
        stop_Button = new JButton("Stop",stop);
        stop_Button.setEnabled(false);
        panel_buttons.add(stop_Button);
       
        Icon like = new ImageIcon(getClass().getResource("like.png"));
        like_Button = new JButton("Like",like);
        panel_buttons.add(like_Button);
       
        Icon loop = new ImageIcon(getClass().getResource("loop.gif"));
        loop_Button = new JButton("Repeat",loop);
        loop_Button.setEnabled(false);
        panel_buttons.add(loop_Button);
       
        Icon open = new ImageIcon(getClass().getResource("Open.png"));
        browse_Button= new JButton("Open",open);
        panel_slider.add(browse_Button);
       
        slider = new JSlider();
        panel_slider.add(slider);
       
        panel_slider.setVisible(true);
        panel_buttons.setVisible(true);
       
        add(panel_slider);
        add(panel_buttons);
       
       
        handlerClass handler = new handlerClass();
        stop_Button.addActionListener(handler);
        loop_Button.addActionListener(handler);
        browse_Button.addActionListener(handler);
        play_Button.addActionListener(handler);       
        pause_Button.addActionListener(handler);
   
        frame1.pack();
        setVisible(true);
    }
     
    private class handlerClass implements ActionListener{
       
       
 public void actionPerformed( ActionEvent actionEvent )
            {
                if(actionEvent.getSource()== browse_Button) {
                chooser();   
              }
              else if( actionEvent.getSource() == play_Button ){
                  run();
                  play_Button.setSelected(false);
                 
               
              }
             
             else if ( actionEvent.getSource() == loop_Button )
             {
             try {  // try the following instructions, if any of them throws an exception (an error occurred)
// then catch the exception and show an appropriate error message to the user
fis = new FileInputStream(file.toString());
bis = new BufferedInputStream(fis);
player = new Player(bis);
player.play();
                       


} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Invalid file or location",
"Error loading file", JOptionPane.ERROR_MESSAGE);
}
             
             }
              else if ( actionEvent.getSource() == stop_Button )
                  stop();
              else if(actionEvent.getSource()==pause_Button)
              {
                 
                 
                 
              }
               // stop AudioClip
              } // end method actionPerformed
            } // end class ButtonHandler
   
   
    void run()
    {
     try {  // try the following instructions, if any of them throws an exception (an error occurred)
// then catch the exception and show an appropriate error message to the user
fis = new FileInputStream(file.toString());
bis = new BufferedInputStream(fis);
player = new Player(bis);
new Thread() {
            public void run() {
                try { player.play(); }
                catch (Exception e) { System.out.println(e); }
            }
        }.start();
                       
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Invalid file or location",
"Error loading file", JOptionPane.ERROR_MESSAGE);
}
     
     
    }
    void stop()
     {
     player.close();
     }
    void chooser()
    {
    fileChooser = new JFileChooser();   
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                  int result = fileChooser.showOpenDialog(null);
                  if (result == JFileChooser.APPROVE_OPTION ) {
file = fileChooser.getSelectedFile();  // user selected a song so get the selected file
}
else {
file = null; // user clicked Cancel button on dialog or an error occurred
}
                  play_Button.setEnabled(true);
                            loop_Button.setEnabled(true);       
                            stop_Button.setEnabled(true);
                  pause_Button.setEnabled(true);
              }
   
    }
          // end class


   
   
 



4
Java / Re: Infinite Loop
« on: February 08, 2015, 09:28:59 PM »


However, this is bad practice.
You shouldn't declare cha as int, if you actually save and test for characters. Use the type char.
The use of in.nextInt() will crash the program if the user enters a character. The correct approach is to read the line into a String instead.

yup, now i get it, actually I am doing a java self study so I haven't tried different things, i will now in other classes. Thanks

5
Java / Re: Infinite Loop
« on: February 08, 2015, 08:48:09 PM »
I know. As I said, remove the semicolon.
as for semicolon ';' the program is not running without it because a do statement must end with a while followed by ; :3

p.s Updated:The program did run without ; but still that was an infinite loop.



do
{

statements

}
while(cond);

6
Java / Re: Infinite Loop
« on: February 08, 2015, 08:42:25 PM »

There is no possibility that cha2 will change its value.
Note that you put a ; there at the end, that ; is the single action you are doing in the loop. Remove the semicolon and you are fine.
Also: That's a reason not to omit the curly braces. Things like these shouldn't happen if you always add them. At least in Java it is convention that you always put braces.
what I wanted to do was that if user inputs 1 the loop should terminate.
Code: [Select]
System.out.println("Wrong Input \n\n"       
+ "Enter 1 To Terminate or any other digit to Continue?");                           
cha2=in.nextInt();



7
Java / Infinite Loop
« on: February 08, 2015, 08:28:17 PM »
Actually I am making a java project about store management just for some practice and I am stuck because of an infinite loop, the main problem i think is in last else or in while condition.What am I doing wrong?
Code: [Select]
public void itemList(){
        Scanner in=new Scanner(System.in);
        int cha1,cha2=0,fruits=10,veg=15,toy=15,groc=35,cha,am1=0;
        System.out.println("\n\n\n\n\nTo Add more Items:1\n\nTo View Existing Items:2");
        cha=in.nextInt();
        while(cha!='q')
        {
            switch(cha)
                    {
                case 1:
                    do{


                        System.out.println("\n\n\n\nEnter amount of:");
                        System.out.println("\nFruits:1\nVegetables:2\nToys:3\nGroceries:4");
                        cha1=in.nextInt();
                        if(cha1==1)
                        {
                            System.out.println("Fruits="+fruits+"\n\nEnter Amount:");
                            fruits+=(am1=in.nextInt());
                            System.out.println("New Amount:"+fruits);
                                            }
                        else if(cha1==2)
                        {
                            System.out.println("Vegetables="+veg+"\n\nEnter Amount:");
                            veg+=(am1=in.nextInt());
                            System.out.println("New Amount:"+veg);
                                            }
                        else if(cha1==3)
                        {
                            System.out.println("Toys="+toy+"\n\nEnter Amount:");
                            toy+=(am1=in.nextInt());
                            System.out.println("New Amount:"+toy);
                                            }
                        else if(cha1==4)
                        {
                            System.out.println("Groceries="+groc+"\n\nEnter Amount:");
                            groc+=(am1=in.nextInt());
                            System.out.println("New Amount:"+groc);
                                            }
                        else
                        {
                            System.out.println("Wrong Input \n\n"
                                    + "Enter 1 To Terminate or any other digit to Continue?");
                            cha2=in.nextInt();
                                            }
                        }
                    while(cha2==1);
                 
                    break;

8
Hacking and Security / Re: opISIS
« on: February 08, 2015, 05:16:24 PM »
I watched the video and done a brief search in le internets. I can't find any legitimate proof that anonyfag is actually doing this.
Some facts some theories don't need to be proved, we just have to put our faith in it. And well anon"fag" isn't an organization with leaders and managers but a bunch of people who are good at redirecting the flow.

9
Hacking and Security / Re: opISIS
« on: February 08, 2015, 03:36:43 PM »
Lol anonfags. Divided by 0? u f0cking w0t m8?

Cool gfx tho.

Well atleast unlike us they have "bawlxz" of steel ;)

10
Hacking and Security / opISIS
« on: February 08, 2015, 03:25:55 PM »
Anonymous took down quite many twitter and fb accounts of people who were recruiting and brainwashing young people to go to syria. They further stated that

"The above video explains the attack was coordinated by “Muslims, Christians, Jews” alike. They are “hackers, crackers, Hacktivist, phishers, agents, spies, or just the guy next door… students, administrators, workers, clerks, unemployed, rich, poor.” They are also “young, or old, gay or straight… from all races, countries, religions, and ethnicity. United as one, divided by zero.”"

Massive Respect for them

http://anonhq.com/anonymous-hacktivists-strike-blow-isis/

11
Projects and Discussion / Re: I Programmed a BF4 Hack
« on: February 04, 2015, 09:23:13 PM »
superb :)

12
Oh my god - you need to work on your coding style more than anything, bro. Indentation sucks, extra spaces suck, formatting sucks as well.




I will :)

13
This ^

Dude whats wrong with the <Enter> spam while you are coding.
Stop putting 1000 empty lines for each line you write, one empty line is just fine I guess(or mostly two if "needed").




I'll try not to repeat old mistakes :) as for this code, i had alot of pressure as there wasn't any time left to submit it, but then again, lame excuses are not tolerable.

14
Don't know if posting links is allowed or not but


www.youtube.com/watch?v=HjRI2AsF3h0

I think that explains it, worth listening.

15
First, for a C++ project, you are using alot of C-style headers. Drop the .h extension, the headers should work just fine. Most of what is in stdio.h should be already in iostream. My compiler has no iostream.h file. You sure need a fine lining between C and C++.


well thank you for the tips :) I'll keep those in mind.

As for .h ext I was using turboc compiler. (restriction by university)

Pages: [1] 2


Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.