Jump to content
  • Advertisement

l jsym l

Member
  • Content Count

    265
  • Joined

  • Last visited

Everything posted by l jsym l

  1. Quick Question:   I am looking for a way to search through a excel file and find the total amount of gallons that a certain location was using.  The excel file would go as follows:   Location:             Product:        Usage New York City     Diesel             30 Billings               Unleaded         42 New York City     Diesel             55 Dallas                 Unleaded        14   (Assuming first column is A1:A5, second is B1:5, and third as C1:C5)   While researching I found my best alternative is using the Index and Match functions to accomplish what I need.   I need to search through this data and find any element that contains new York city and diesel.  If them two arguments exist I need to add up the total amount of usage.    Im not looking for special functions rather just using Excel.   If anyone can help it would be greatly appreciated.  Thanks.
  2. l jsym l

    Iterator troubles

    ah yes. Just figured it out, that was a big duh on my part. Thanks
  3. l jsym l

    Iterator troubles

    Hey, Im creating an array of lists. I need to be able to iterate through the list for printing and comparison reasons. This code is not completely done by any means so the code I'll be posting is very rough. I'm just getting an error that is saying: "expression must have class type". Im getting this error where im creating my for loop for the iterator. If anyone has any suggestions let me know. Thanks! #include "LinkingHash.h" int LinkingHash::getHash( string str ) { int result = 0; for ( unsigned int i = 0; i < str.length(); i++ ) { result = result + ( int( str ) ); } return result % 13; } void LinkingHash::addToHash( string str ) { hashIndex = getHash( str ); hashTable[hashIndex].push_back( str ); //cout << hashTable[hashIndex].back() << endl; list<string>::const_iterator it; for( it = hashTable.begin(); it != hashTable.end(); it++) { } } void LinkingHash::deleteFromHash( string str ) { hashIndex = getHash( str ); vector<string> vec; for( unsigned int i = 0; i < hashTable[hashIndex].size(); i++ ) { string temp = hashTable[hashIndex].back(); hashTable[hashIndex].pop_back(); vec.push_back( temp ); if ( vec.back() == str ) { vec.pop_back(); } } for( unsigned int i = 0; i < vec.size(); i++ ) { string temp = vec.back(); vec.pop_back(); hashTable[hashIndex].push_back( temp ); } } void LinkingHash::printHashTable() { int index = 0; vector<string> vec; while( index < SIZE ) { cout << index << ") "; /*list<string>::const_iterator Iterator; for(Iterator = hashTable.begin(); Iterator != hashTable.end(); Iterator++)*/ for( unsigned int i = 0; i < hashTable[index].size(); i++ ) { string temp = hashTable[hashIndex].back(); hashTable[hashIndex].pop_back(); vec.push_back( temp ); } for( unsigned int j = 0; j < vec.size(); j++ ) { string temp = vec.back(); vec.pop_back(); cout << temp << " "; hashTable[hashIndex].push_back( temp ); } cout << endl; index++; } }
  4. l jsym l

    PL/SQL

    Hey, I have a question, yes on homework, and I can't seem to figure out a little part of the question out. I'm suppose to create a procedure and do this and that within it. However, I was just wondering if there is a simple select statement where I can get for example, The total number of one certain type of cars for 30,000 dollars. I was thinking something like SELECT COUNT(*) FROM CARS C WHERE C.NAME = 'LAMBO' AND ( SELECT SUM( C1.PRICE ) FROM CARS C1 WHERE C1.NAME = 'LAMBO' ) >= 30000; This is just an example not the actual question. I know this would only return 1 row. So i Guess I'm just unsure how to handle this.
  5. l jsym l

    PL/SQL

    K. Ill try to be more clear. Say a lambo costs 300,000 USD now. I need to see how much Lambos I can buy with 1,000,000 USD. So my answer should be 3.
  6. l jsym l

    PL/SQL

    What im looking for is like this: Say a lambo costs 10,000. Just an example i know its WAY off. Therefore I should get 3 rows considering I can buy 3 lambos for 30,000 or less. Is this any better?
  7. Hey, I did a project for a Java class that I am currently taking to get my Bachelors Degree. I'm still pretty new to programming and no expert by any means. Anyway, I finished this assignment and handed it in, then just yesterday I was told by my professor that how I coded my classes are completely wrong and "I don't have any idea how to program". He says I'm not suppose to code a random generator in a class. Is this true? Also, I got all the correct output for this program and it runs successfully every time I run it. The program has a warehouse, producers, and consumers. The user enters min and max values for all the classes and then the random generator generates how much foos the warehouse can hold, how much foos the producers put in the warehouse, and how much foos the consumers take out. The consumers and producers are a queue that just keep rotating as they are called. Here is my code: Warehouse Class import java.util.*; public class Producer { // Random generator used to generate random numbers for input Random generator = new Random(); // Queue used to store amounts Queue<Integer> pQueue = new LinkedList<Integer>(); // Private variables used for Producer Class private int foos_max, foos_min; private int producer_max, producer_min; private int total_produced = 0, entered = 0;; /* * Default Constructor: Sets foos_min, foos_max, producer_max, and producer_min to default 0. */ public Producer() { this.foos_max = 0; this.foos_min = 0; this.producer_max = 0; this.producer_min = 0; } /* * Default Constructor: Initializes variables to input parameter * @param a Initial value of producer_min * @param b Initial value of producer_max * @param c Initial value of foos_min * @param d Initial value of foos_max */ public Producer( int a, int b, int c, int d ) { // Producers Min and Max this.producer_min = a; this.producer_max = b; // Foos Min and Max this.foos_min = c; this.foos_max = d; // Generate Random number for number of producers. int num_producers = generator.nextInt( producer_max - producer_min ) + producer_min; for( int i = 0; i < num_producers; i++ ) { int temp = generator.nextInt( foos_max - foos_min + 1) + foos_min; pQueue.add( temp ); } } /* * produceFoo() Adds the amount of the front of pQueue to the warehouse * @param a The warehouse that is getting "foos" added to it */ public void produceFoo( Warehouse a ) { if ( ( pQueue.element() + a.getFoos() ) <= a.getMax() ) { int temp = pQueue.remove(); a.addFoo( temp ); total_produced = total_produced + temp; pQueue.add( temp ); entered++; } } /* * getSize() Returns the size of pQueue */ public int getSize() { return pQueue.size(); } /* * toString() Returns a String of the elements in the queue. */ public String toString() { String tempStr = ""; for ( int i = 0; i < pQueue.size(); i++ ) { int tempInt = pQueue.remove(); tempStr = tempStr + " " + tempInt; pQueue.add( tempInt ); } return tempStr; } /* * getNext() Returns the first element in the queue */ public int getNext() { return pQueue.element(); } /* * getProduced() Returns total_produced, the total amount of "foos" produced */ public int getProduced() { return total_produced; } /* * getEntered() Returns entered, the total amount of times "foos" were entered into warehouse */ public int getEntered() { return entered; } } Consumer Class import java.util.*; public class Consumer { // Random generator used to generate random numbers for input Random generator = new Random(); // Queue used to store amounts Queue<Integer> cQueue = new LinkedList<Integer>(); // Private variables used in Consumer Class private int consumer_min, consumer_max; private int foos_min, foos_max; private int total_consumed = 0, entered = 0; /* * Default Constructor: Sets foos_max, foos_min, consumer_max, and consumer_min to default 0 */ public Consumer() { this.foos_max = 0; this.foos_min = 0; this.consumer_max = 0; this.consumer_min = 0; } /* * Default Constructor: Initializes variables to input parameter * @param a Initial value of consumer_min * @param b Initial value of consumer_max * @param c Initial value of foos_min * @param d Initial value of foos_max */ public Consumer( int a, int b, int c, int d ) { // Consumer Min and Max this.consumer_min = a; this.consumer_max = b; // Foos Min and Max this.foos_min = c; this.foos_max = d; // Generate random number for number of producers int num_consumers = generator.nextInt( consumer_max - consumer_min ) + consumer_min; for( int i = 0; i < num_consumers; i++ ) { // Get random number to put into queue int rTemp = generator.nextInt( foos_max - foos_min + 1 ) + foos_min; // Set random number into cQueue cQueue.add( rTemp ); } } /* * consumeFoo() Removes the amount at the front of cQueue from warehouse * @param a The warehouse that is getting "foos" removed from it */ public void consumeFoo( Warehouse a ) { if ( cQueue.element() <= a.getFoos() ) { int temp = cQueue.remove(); a.removeFoo( temp ); total_consumed = total_consumed + temp; cQueue.add( temp ); entered++; } } /* * getSize() Returns the size of cQueue */ public int getSize() { return cQueue.size(); } /* * toString() Returns tempStr, a string of all the elements in the queue */ public String toString() { String tempStr = ""; for ( int i = 0; i < cQueue.size(); i++ ) { int tempInt = cQueue.remove(); tempStr = tempStr + " " + tempInt; cQueue.add( tempInt ); } return tempStr; } /* * getNext() Returns the first element in the queue */ public int getNext() { return cQueue.element(); } /* * getConsumed() Returns total_consumed, the total number of "foos" consumed */ public int getConsumed() { return total_consumed; } /* * getEntered() Returns entered, the total number of times "foos" were consumed from the warehouse */ public int getEntered() { return entered; } } Producer Class import java.util.*; public class Producer { // Random generator used to generate random numbers for input Random generator = new Random(); // Queue used to store amounts Queue<Integer> pQueue = new LinkedList<Integer>(); // Private variables used for Producer Class private int foos_max, foos_min; private int producer_max, producer_min; private int total_produced = 0, entered = 0;; /* * Default Constructor: Sets foos_min, foos_max, producer_max, and producer_min to default 0. */ public Producer() { this.foos_max = 0; this.foos_min = 0; this.producer_max = 0; this.producer_min = 0; } /* * Default Constructor: Initializes variables to input parameter * @param a Initial value of producer_min * @param b Initial value of producer_max * @param c Initial value of foos_min * @param d Initial value of foos_max */ public Producer( int a, int b, int c, int d ) { // Producers Min and Max this.producer_min = a; this.producer_max = b; // Foos Min and Max this.foos_min = c; this.foos_max = d; // Generate Random number for number of producers. int num_producers = generator.nextInt( producer_max - producer_min ) + producer_min; for( int i = 0; i < num_producers; i++ ) { int temp = generator.nextInt( foos_max - foos_min + 1) + foos_min; pQueue.add( temp ); } } /* * produceFoo() Adds the amount of the front of pQueue to the warehouse * @param a The warehouse that is getting "foos" added to it */ public void produceFoo( Warehouse a ) { if ( ( pQueue.element() + a.getFoos() ) <= a.getMax() ) { int temp = pQueue.remove(); a.addFoo( temp ); total_produced = total_produced + temp; pQueue.add( temp ); entered++; } } /* * getSize() Returns the size of pQueue */ public int getSize() { return pQueue.size(); } /* * toString() Returns a String of the elements in the queue. */ public String toString() { String tempStr = ""; for ( int i = 0; i < pQueue.size(); i++ ) { int tempInt = pQueue.remove(); tempStr = tempStr + " " + tempInt; pQueue.add( tempInt ); } return tempStr; } /* * getNext() Returns the first element in the queue */ public int getNext() { return pQueue.element(); } /* * getProduced() Returns total_produced, the total amount of "foos" produced */ public int getProduced() { return total_produced; } /* * getEntered() Returns entered, the total amount of times "foos" were entered into warehouse */ public int getEntered() { return entered; } } Main Class - testing file import java.util.*; import java.io.*; public class Main { // Number of ticks the simulation has executed static int simTicks = 0; public static void main( String[] args) { // Create a object of Random used for generating random numbers Random generator = new Random(); // Create a scanner object for system input Scanner scanner = new Scanner( System.in ); // Creating variables for simulation int warehouse_min, warehouse_max; int p_c_min, p_c_max; int foos_min, foos_max; // Get Max and Min Values for the warehouse System.out.println( "What is the minimum that the warehouse can hold?"); warehouse_min = scanner.nextInt(); System.out.println( "What is the maximum that the warehouse can hold?"); warehouse_max = scanner.nextInt(); // Creating the warehouse Warehouse wHouse = new Warehouse( warehouse_min, warehouse_max ); // Get max and Min Values for Producers and Consumers System.out.println( "What is the minimum number of producers and consumers?" ); p_c_min = scanner.nextInt(); System.out.println( "What is the maximum number of producers and consumers?" ); p_c_max = scanner.nextInt(); // Get the max and min values for foos. System.out.println( "What is the minimum number of foos that can be produced or consumed?" ); foos_min = scanner.nextInt(); System.out.println( "What is the maximum number of food that can be produced or consumed?" ); foos_max = scanner.nextInt(); // Creating the Consumers and Producers Queue Producer pQueue = new Producer( p_c_min, p_c_max, foos_min, foos_max ); Consumer cQueue = new Consumer( p_c_min, p_c_max, foos_min, foos_max ); // Code for Two Simulation Ticks // Try block for exception handling try { // Create a PrintWriter that writes to file "output.txt" FileWriter fw = new FileWriter( "output.txt" ); PrintWriter pw = new PrintWriter( fw ); // Do this until "foos" = warehouse max while ( wHouse.getFoos() != wHouse.getMax() ) { // Creating random coin flip int flip = generator.nextInt( 2 ); // If 0 then producer is added if ( flip == 0 ) { pQueue.produceFoo( wHouse ); } // If 1 then consumer is added if ( flip == 1 ) { cQueue.consumeFoo( wHouse ); } simTicks++; // Print data to file print( wHouse, pQueue, cQueue, pw ); } // Do this until "foos" = 0 while ( wHouse.getFoos() != 0 ) { // Creating random coin flip int flip = generator.nextInt( 2 ); // If 0 then producer is added if ( flip == 0 ) { pQueue.produceFoo( wHouse ); } // If 1 then consumer is added if ( flip == 1 ) { cQueue.consumeFoo( wHouse ); } simTicks++; // Print data to file print( wHouse, pQueue, cQueue, pw ); } // Do this until "foos" = warehouse max while ( wHouse.getFoos() != wHouse.getMax() ) { // Creating random coin flip int flip = generator.nextInt( 2 ); // If 0 then producer is added if ( flip == 0 ) { pQueue.produceFoo( wHouse ); } // If 1 then consumer is added if ( flip == 1 ) { cQueue.consumeFoo( wHouse ); } simTicks++; // Print data to file print( wHouse, pQueue, cQueue, pw ); } // Do this until "foos" = 0 while ( wHouse.getFoos() != 0 ) { // Creating random coin flip int flip = generator.nextInt( 2 ); // If 0 then producer is added if ( flip == 0 ) { pQueue.produceFoo( wHouse ); } // If 1 then consumer is added if ( flip == 1 ) { cQueue.consumeFoo( wHouse ); } simTicks++; // Print data to file print( wHouse, pQueue, cQueue, pw ); } // Close the output file pw.close(); } // FileNotFoundException Handler catch ( FileNotFoundException e ) { System.out.println( "File Not Found Exception Error. " ); } // IOException Handler catch (IOException e) { System.out.println( "I/O Exception Error." ); } System.out.println( "\n" ); // Recursion Call System.out.println( "Please enter the number of base stars: " ); int stars = scanner.nextInt(); // Call the recursive function for Recursive Problem recursion( stars, stars ); } /* * print() Prints output to an output file * @param w Warehouse that contains information to be printed from * @param p Producer that contains information to be printed from * @param c Consumer that contains information to be printed from */ public static void print( Warehouse w, Producer p, Consumer c, PrintWriter pw ) { // The data to be printed to the output file pw.println( "The arrangement of Customers: " + c.toString() ); pw.println( "The arrangement of Producers: " + p.toString() ); pw.println( "The number of 'foos' in the Warehouse: " + w.getFoos() ); pw.println( "The number of 'foos' each Producer seeks to store: " + p.getNext() ); pw.println( "The number of 'foos' Consumer's requires: " + c.getNext() ); pw.println( "The total number of 'foos' Producers has stored: " + p.getProduced() ); pw.println( "The total number of 'foos' Consumers have consumed: " + c.getConsumed() ); pw.println( "The number of times Producers have entered Warehouse: " + p.getEntered() ); pw.println( "The number of time Consumers have entered Warehouse: " + c.getEntered() ); pw.println( "The number of Simulation Ticks: " + simTicks ); pw.println(""); } // Recursion Method /* * recursion() Uses recursion to print out a sequence of stars * @param n Number or rows and stars to be printed on each row * @param max Total number of stars for the base line, needed for spacing */ public static void recursion( int n, int max ) { //int max = if ( n == 1 ) { printing( 1, max ); } else { recursion( n - 1, max); printing( n, max ); } } /* * printing() Uses spacing to print out formatted output * @param n Number of stars to print out * @param max Max number of characters, used for spacing */ public static void printing( int n, int max ) { // Loops for iteration and spacing int count = max - n; for( int i = 0; i < count; i++ ) { System.out.print( " " ); } for( int i = 0; i < n; i++ ) { System.out.print( "* " ); } System.out.println(); } } At the end of the main class - test file there is a little bit of recursion. This is an add on onto the assignment, no problems here.
  8. Got my grade back. I received a 50% on it and according to him my Recursion problem was completely wrong? I don't get it.
  9. He was referring to me using the Random Instance at all. I know I should have made a separate method outside of the class and just passed it the value but according to him what I did is completely wrong and I am no good at programming. I don't know, I guess I was just wondering if it was "that" bad that I did this in the class.
  10. Yes, The requirements were to use random numbers. The only part of the program he really bashed me on was the random generator in my classes. I know I could code it different and generate the random values in say the main class, them pass them to the class. However, by the sounds of it he's not going to give me much credit at all for something I could fix in a matter of time.
  11. If any questions please just ask. Thank you
  12. l jsym l

    Recursion

    Hey, I'm fooling around with Recursion in JAVA. Anyways, I was just wondering if there is anyway to make this: * * * * * * * * * * * * * * * In java using recursion. I can get it to print out: * ** *** **** ***** However I cant seem to figure out the spacing. Im kinda wanting to use two separate recursion functions. One for the stars and one for the spacing but cant seem to wrap my head around it
  13. l jsym l

    ASUS Desktop Internet Problem

    I have all of my drivers and my setting are set up correctly. I'm a IT guy so I know how to get the internet working. Im just wondering if its a possibility that the internet card went out or something? It says I am connected for brief moments at a time when I can never surf the internet. All the drivers are there, i am using DHCP and another asus desktop that I have, which is also hardlined into the router, works good. Im guessing its hardware now but idk.
  14. Hey, I have an Asus Desktop that I purchased from best buy. Anyways, I've had it for about half a year and has been working amazing for me. The only thing I changed in it was I installed a wireless internet card, however I do not use it because I hardline in. A couple of days ago I got kicked off the internet and now it keeps telling me I have limited or no connection. I took out the wireless card thinking that it was trying to use that when maybe it was fried, but still nothing works. When I hardline directly into the router I still have no internet access. I was just wondering if anyone else has had this problem, and if so how have you fixed it. Thanks, If you need any other information on my model or anything just let me know and I will be happy to get it for you.
  15. l jsym l

    ASUS Desktop Internet Problem

    Yes, multiple other connections in the router. However. When I do try using the internet on my asus it will kick everybody off the router
  16. l jsym l

    Question using Log

    Hey, I was just wondering if there was a possible log function or any function, or way, that I could do this. I want to get three separate integers: int a = 0x1; int b = 0x0; int c = 0x0d; However, I want to put these integers so the new integer intact is 0x100d. I understand if I have 100d and just do int num1 = (intTemp / 0x10000); int rem1 = (intTemp % 0x10000); int num2 = ( rem1 / 0x1000 ); int rem2 = ( rem1 % 0x1000 ); int num3 = rem2; It will split it up reverse of how I want it done now. Is there a way to reverse what I did here^^ ? Thanks.
  17. l jsym l

    Question using Log

    Alright thanks! I'll see if I can figure it out from that
  18. l jsym l

    Input File in C++

    Hey, I'm trying to read in an input file for a program that I am creating and am running into some problems. The way I have it set up right now is working but it could be troublesome in the future. I was just wondering if there was a way to read in a input file such as: FFFFFFFF M LLLLLLLLLL John T Smith What I want to do is read in these strings separately according to the column widths (i.e FFFFFFF M LLLLLLLLLL) I know I could use a substring for these, however, when I have to use them in the future I dont want to have something like if ( a == "John ") instead I want if (a == "John") without the extra bits at the end. I am unsure if I am explaining myself clear enough or not but I tried my best to make it understandable.
  19. Hey, I was just wondering if there was a certain way to make an array that doesn't have a definite size. I am writing a program that might possibly need to add elements to an array. I was just wondering if there was a certain way to make the array bounds be infinite. I hope I'm explaining myself clear enough. If anyone has any ideas that would be great. Thanks!
  20. l jsym l

    Quick Question on the size of an array.

    alright thanks! I didn't even think about that. big DUH on my part. Thanks!
  21. l jsym l

    Hex in Two's Compliment.

    alright thanks everybody I'll try figuring it out.
  22. Hey, I was just wondering if there is any possible way in c++ to represent a hex number in two's compliment. By this I mean. Say i have a hexadecimal value of 7FF, or 111 1111 1111 in binary. I need to represent this in two's compliment so I can get a value of -1 instead of a value of 2046. If I didn't make myself clear just let me know and I'll try to explain what I mean better. Thanks.
  23. l jsym l

    Hex in Two's Compliment.

    Yes it is for an assignment sort of so I would like to figure it out myself but I do got a question. Do you know where I can find any information on doing 'sign extends'?
  24. l jsym l

    Hex in Two's Compliment.

    K thats what I was thinking too but was unsure of how to do it
  25. l jsym l

    Hex in Two's Compliment.

    I simply stated if I was being clear enough I would clear it up. What I meant is i have a Hex number 7FF. I also stated that I didn't want it to output 2046, instead I want it to output -1. Therefore it is stored as an int such as int a = 0x7FF; Thanks for the reinterpret_cast though sicrane. I'm trying to figure it out as we speak.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!