Sapperm's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
New Members
Active Posts:
15 (0.02 per day)
Joined:
31-October 12
Profile Views:
244
Last Active:
User is offline Sep 18 2013 08:36 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Sapperm has not set their status

Posts I've Made

  1. In Topic: Reading data from an array into an object

    Posted 16 Sep 2013

    Well I worked more on it as soon as I posted the question. I think I found a valid solution by using array lists.
    *I made an array list
    *populated the list
    *converted the list to a int array via loop
    *sent in the array to the constructor
    *used .clear to clear the list and start over

    import java.util.*;
    import java.io.*;
    /**
     * 
     * @author 
     *
     */
    public class Lab2 {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		
    		Grades[] classArray;
    	     classArray = new Grades[4];
    	
    	     ArrayList<Integer> gradeList = new ArrayList<Integer>();
    		
    	     
    	  
    		int [] grades;
    		grades = new int[1];
    		
    		String name;
    		  
            int counter = 0;
    		
            
    		Scanner in = null;
    		try {
    		    in = new Scanner(new File("data.txt"));
    		} catch (FileNotFoundException exception) {
    		    System.err.println("failed to open data.txt");
    		    System.exit(1);
    		}
    		int j = 0;
    		while (in.hasNext()) {
    			name = in.next();
    			
    		
    		    while (in.hasNextInt()) {
    		    	int grade = in.nextInt();
    			  
    		    	gradeList.add(grade);
    				
    		//		if (counter == grades.length) {
    			//		
    			//		grades = Arrays.copyOf(grades, 2 * grades.length);
    		//		}
    				
    				
    				
    			//	grades[counter] = grade;
    				counter++;
    	
    		    }
    		 
    		   
    		    grades = new int[gradeList.size()];
    		    for (int index = 0; index < gradeList.size(); index++) {
    		        grades[index] = gradeList.get(index);
    		    }
    		   // System.out.println("gradelist.size = "+ gradeList.size());
    		   // grades = Arrays.copyOf(grades, counter);
    		   
    		    
    		    classArray[j] = new Grades(name,grades);
    		    gradeList.clear();
    		 
    		    j++;
    		 
    		}
    		//grades = Arrays.copyOf(grades, counter);
    //		Arrays.sort(grades);
    	/*
    		for(int i = 0; i < counter; i++){
    		    
    			System.out.printf("counter = %d\n",grades[i]);
    		
    		}
    		*/
    
    		testGrades(classArray[0]);
    		testGrades(classArray[1]);
    		testGrades(classArray[2]);
    		testGrades(classArray[3]);
    	}//end main
    	
    	public static void testGrades(Grades grades) {
    	    System.out.println(grades.toString()); 
    	    System.out.printf("\tName:    %s\n", grades.getName());
    	    System.out.printf("\tLength:  %d\n", grades.length());
    	    System.out.printf("\tAverage: %.2f\n", grades.average());
    	    System.out.printf("\tMedian:  %.1f\n", grades.median());
    	    System.out.printf("\tMaximum: %d\n", grades.maximum());
    	    System.out.printf("\tMininum: %d\n", grades.minimum());
    	}
    
    }//end class
    
    
    
  2. In Topic: Inserting strings to binary trees

    Posted 15 Aug 2013

    I was using all of the various printf() statements in the program to test where data was being read and stored properly. As it turns out it all was.

    I found the problem at line 69. I had a == instead of a =.
  3. In Topic: hi i really want to learn C++ but where do i go?

    Posted 14 Aug 2013

    Some questions you may want to ask your self.
    Why do I want to learn C++?
    What do I want to accomplish?
    How much time can I spend on learning?

    Based on these answers you will discover a variety of methods that will work best for you. If you are looking for a career path, and formal instruction, maybe a university would be best. On the other hand, you may be looking to learn on the side casually.

    There are many tutorials on this site. There are also vast amounts of tutorials on youtube for all experience levels. The best thing to do is expose your self to all of these mediums and see what helps you learn the most.
  4. In Topic: Reading in data from a file

    Posted 8 Apr 2013

    Very messy and I'm sure a very long way around, but this is how I got it to work....
    also ignore any // slashed out code. That was left over from trying a lot of stuff.

    Press ENTER or type command to continue
    #include "tree23.c"
    #include <string.h>
    
    
    
    int main(int argc, char *argv[])
    {
       FILE *fp;
       int a,b,c,total;
       char string[100];
       char x,y,z,j,k;
       char *point;
       fp = fopen(argv[1],"r");
      char delim1[] = "(";
      char delim2[] = ")";
      char delim3[] = ",";
    //   while( total =  fscanf(fp,"%d%d%d",&a,&b,&c) > 0 ){
      // printf("here\n");
       while(fgets(string,100,fp)!= NULL ){
    //   sscanf(string,"%d%d%d",&a,&b,&c);
     //  a =(int) string[0];
    //   b =(int) string[3];
     //  c =(int) string[6];
    
       point = strtok(string,delim2);
       point = strtok(point,delim1);
      // point = strtok(point,delim3);
       sscanf(point,"%d%c%d%c%d",&a,&x,&b,&y,&c);
    
     //  printf("total = %d \n",total);
       printf("First = %d Second = %d Third = %d\n",a,b,c);
      // printf("First = %c Second = %c Third = %c 4th = %c\n",x,y,z,j);
       }
       return 0;
    
    }
    ~
    
    
    
  5. In Topic: Reading in data from a file

    Posted 8 Apr 2013

    Thanks for that I'll get to work on that right away. Is there a reason for when the data is say three ints
    such as 78 67 62 you can read it in with scanf("&d&d&d",&a,&b,&c); and not worry about the \n?

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Sapperm hasn't added any friends yet.

Comments

Sapperm has no profile comments yet. Why not say hello?