Search Results

Search found 1552 results on 63 pages for 'homework'.

Page 3/63 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Double Linked List header node keeps returning first value as 0

    - by Craig
    I will preface to say that this is my first question. I am currently getting my Masters degree in Information Security and I had to take C++ programming this semester. So this is homework related. I am not looking for you to answer my homework but I am running into a peculiar situation. I have created the program to work with a doubly linked list and everything works fine. However when I have the user create a list of values the first node keeps returning 0. I have tried finding some reading on this and I cannot locate any reference to it. My question is then is the header node(first node) always going to be zero? Or am I doing something wrong. case: 'C': cout<<"Please enter a list:"<<endl; while(n!=-999){ myList.insert(n); cin>> n;} break; I now enter: 12321, 1234,64564,346346. The results in 0, 12321, 1234, 64564,346346. Is this what should happen or am I doing something wrong? Also as this is my first post please feel free to criticize or teach me how to color code the keywords. Anyway this is a homework assignment so I am only looking for guidance and constructive criticism. Thank you all in advance So I cannot figure out the comment sections on this forum so I will edit the original post The first section is the constructor code: template <class Type> doublyLinkedList<Type>::doublyLinkedList() { first= NULL; last = NULL; count = 0; } Then there is my insert function : template <class Type> void doublyLinkedList<Type>::insert(const Type& insertItem) { nodeType<Type> *current; //pointer to traverse the list nodeType<Type> *trailCurrent; //pointer just before current nodeType<Type> *newNode; //pointer to create a node bool found; newNode = new nodeType<Type>; //create the node newNode->info = insertItem; //store the new item in the node newNode->next = NULL; newNode->back = NULL; if(first == NULL) //if the list is empty, newNode is //the only node { first = newNode; last = newNode; count++; } else { found = false; current = first; while (current != NULL && !found) //search the list if (current->info >= insertItem) found = true; else { trailCurrent = current; current = current->next; } if (current == first) //insert newNode before first { first->back = newNode; newNode->next = first; first = newNode; count++; } else { //insert newNode between trailCurrent and current if (current != NULL) { trailCurrent->next = newNode; newNode->back = trailCurrent; newNode->next = current; current->back = newNode; } else { trailCurrent->next = newNode; newNode->back = trailCurrent; last = newNode; } count++; }//end else }//end else }//end Then I have an initialization function too: template <class Type> void doublyLinkedList<Type>::initializeList() { destroy(); } Did I miss anything?

    Read the article

  • sqrt(int_value + 0.0) -- Does it have a purpose?

    - by Earlz
    Hello, while doing some homework in my very strange C++ book, which I've been told before to throw away, had a very peculiar code segment. I know homework stuff always throws in extra "mystery" to try to confuse you like indenting 2 lines after a single-statement for-loop. But this one I'm confused on because it seems to serve some real-purpose. basically it is like this: int counter=10; ... if(pow(floor(sqrt(counter+0.0)),2) == counter) ... I'm interested in this part especially: sqrt(counter+0.0) Is there some purpose to the +0.0? Is this the poormans way of doing a static cast to a double? Does this avoid some compiler warning on some compiler I do not use? The entire program printed the exact same thing and compiled without warnings on g++ whenever I left out the +0.0 part. Maybe I'm not using a weird enough compiler? Edit: Also, does gcc just break standard and not make an error for Ambiguous reference since sqrt can take 3 different types of parameters? [earlz@EarlzBeta-~/projects/homework1] $ cat calc.cpp #include <cmath> int main(){ int counter=0; sqrt(counter); } [earlz@EarlzBeta-~/projects/homework1] $ g++ calc.cpp /usr/lib/libstdc++.so.47.0: warning: strcpy() is almost always misused, please use strlcpy() /usr/lib/libstdc++.so.47.0: warning: strcat() is almost always misused, please use strlcat() [earlz@EarlzBeta-~/projects/homework1] $

    Read the article

  • Validating User Input? C#

    - by Alex
    Hi, in an assignment, I have designed a input validation loop in C#, and I would like it to be able to check for the correct input format. I'm not for sure, but I think my designed loop is not checking the type of input, just what char is entered. I know I could use a try-catch block, but shouldn't you only use exceptions for exceptional situations? This is not an exceptional situation, because I expect that the user would enter an incorrect value. Input validation is not part of my assignment, so the loop is in a homework assignment, but is not part of the homework assignment. Question: Is there a way I could redesign this loop so that it checks for valid input type as well? Code: do { Console.Write("Do you wish to enter another complex number?: (Y or N)"); response = char.Parse(Console.ReadLine()); response = char.ToUpper(response); if (response != 'Y' && response != 'N') Console.WriteLine("You must respond Y or N!"); } while (response != 'Y' && response != 'N'); Thanks!!

    Read the article

  • How to create extensible dynamic array in Java without using pre-made classes?

    - by AndrejaKo
    Yeah, it's a homework question, so givemetehkodezplsthx! :) Anyway, here's what I need to do: I need to have a class which will have among its attributes array of objects of another class. The proper way to do this in my opinion would be to use something like LinkedList, Vector or similar. Unfortunately, last time I did that, I got fire and brimstone from my professor, because according to his belief I was using advanced stuff without understanding basics. Now next obvious solution would be to create array with fixed number of elements and add checks to get and set which will see if the array is full. If it is full, they'd create new bigger array, copy older array's data to the new array and return the new array to the caller. If it's mostly empty, they'd create new smaller array and move data from old array to new. To me this looks a bit stupid. For my homework, there probably won't be more that 3 elements in an array, but I'd like to make a scalable solution without manually calculating statistics about how often is array filled, what is the average number of new elements added, then using results of calculation to calculate number of elements in new array and so on. By the way, there is no need to remove elements from the middle of the array. Any tips?

    Read the article

  • Find the order among tasks in a company by using prolog?

    - by Cem
    First of all,I wish a happy new year for everyone.I searched more and worked a lot but I could not solve this question.I am quite a new in prolog and I must do this homework. In my homework,the question is like this: Write a prolog program that determines a valid order for the tasks to be carried out in a company. The prolog program will consist of a set of "before" predicates which denotes the order between task pairs. Here is an example; before(a,b). before(a,e). before(d,c). before(b,c). before(c,e). Here, task a should be carried before tasks b and e, d before c and so on. Hence a valid ordering of the tasks would be [a, b, d, c, e]. The order predicate in your program will be queried as follows. ?- order([a,b,c,d,e],X). X = [a, b, d, c, e] ; X = [a, d, b, c, e] ; X = [d, a, b, c, e] ; false. Hint: Try to generate different orders for the tasks (permutation) and then check if the order is consistent with the "before" relationships given. Even if you can generate a single valid order, you will get reasonable partial credits.

    Read the article

  • Javascript mouseover image failure

    - by CaptainTeancum
    This is what I have so far, I have been watching a ton of Javascript videos and I feel I mimicked them solid but this is still not functioning as I want. Than being, it changes from logo1 to logo2 on mousover. This is homework. However homework that is important to me so any help or guidance would be appreciated. </head> <body> <p> <div> <script type="text/javascript"> // Pre load images for rollover function imgOver(id) { document.getElementById(id).src="logo1.jpg"; } function imgOut(id) { document.getElementById(id).src="logo2.jpg"; } </script> <a href="#" onmouseover="imgOver('logo1');" onmouseout="imgOut('logo2')"> <img alt="logo" height="150" src="images/Logo1.jpeg" width="110" /> </a> </div> </body> </html>

    Read the article

  • it means quick-select algorithm?

    - by matin1234
    Hi, I have a question from my homework. I think my teacher needs an algorithm like quick select for this question is this correct? The question: Following a program (Subroutine) as a "black box" is given (for example, inside it is not clear and we do not even inside it) with the worst case linear time, can find the middle of n elements. Using this black box, get a simple linear algorithm that takes input i and find the element which its rank is equal to i (among the n elements) Thanks.

    Read the article

  • Good use of recursion in chess programming?

    - by JDelage
    Hi, As part of a homework assignment, I have to program a simple chess game in Java. I was thinking of taking the opportunity to experiment with recursion, and I was wondering if there's an obvious candidate in chess for recursive code? Thank you, JDelage

    Read the article

  • Generate all unique substrings for given string

    - by Yuval A
    Given a string s, what is the fastest method to generate a set of all its unique substrings? Example: for str = "aba" we would get substrs={"a", "b", "ab", "ba", "aba"}. The naive algorithm would be to traverse the entire string generating substrings in length 1..n in each iteration, yielding an O(n^2) upper bound. Is a better bound possible? (this is technically homework, so pointers-only are welcome as well)

    Read the article

  • Counting Alphabetic Characters That Are Contained in an Array with C

    - by Craig
    Hello everyone, I am having trouble with a homework question that I've been working at for quite some time. I don't know exactly why the question is asking and need some clarification on that and also a push in the right direction. Here is the question: (2) Solve this problem using one single subscripted array of counters. The program uses an array of characters defined using the C initialization feature. The program counts the number of each of the alphabetic characters a to z (only lower case characters are counted) and prints a report (in a neat table) of the number of occurrences of each lower case character found. Only print the counts for the letters that occur at least once. That is do not print a count if it is zero. DO NOT use a switch statement in your solution. NOTE: if x is of type char, x-‘a’ is the difference between the ASCII codes for the character in x and the character ‘a’. For example if x holds the character ‘c’ then x-‘a’ has the value 2, while if x holds the character ‘d’, then x-‘a’ has the value 3. Provide test results using the following string: “This is an example of text for exercise (2).” And here is my source code so far: #include<stdio.h> int main() { char c[] = "This is an example of text for exercise (2)."; char d[26]; int i; int j = 0; int k; j = 0; //char s = 97; for(i = 0; i < sizeof(c); i++) { for(s = 'a'; s < 'z'; s++){ if( c[i] == s){ k++; printf("%c,%d\n", s, k); k = 0; } } } return 0; } As you can see, my current solution is a little anemic. Thanks for the help, and I know everyone on the net doesn't necessarily like helping with other people's homework. ;P

    Read the article

  • Simulated Annealing Applications

    - by Andrei Vajna II
    Do you know any real applications for Simulated Annealing? Simulated Annealing is a heuristic algorithm used for problems like the traveling salesman or the knapsack problem. And yes, this is homework. I have to write a paper on this, and I thought this would be the best starting point. Perhaps someone actually works on a project that relies on Simulated Annealing.

    Read the article

  • Doxygen dependencies to manage during install

    - by aCuria
    Hi, i am supposed to document my code with doxygen for a homework assignment, but i have problems getting doxygen to run. I have a Doxyfile provided, and have just installed doxygen on my machine. When i enter the command to run doxygen, "doxygen Doxyfile" I get the following error: failed to run html help compiler on index.hhp can anyone clue me into what i am doing wrong? Thanks

    Read the article

  • Shell loops using non-integers?

    - by mary
    I wrote a .sh file to compile and run a few programs for a homework assignment. I have a "for" loop in the script, but it won't work unless I use only integers: #!/bin/bash for (( i=10; i<=100000; i+=100)) do ./hw3_2_2 $i done The variable $i is an input for the program hw3_2_2, and I have non-integer values I'd like to use. How could I loop through running the code with a list of decimal numbers?

    Read the article

  • Specifying Language for a grammar

    - by darkie15
    Hi All, Is there any specific methodology followed to specify a language for given grammar ?? i.e. Is it necessary to run all the production rules given in a grammar to determine the language it represents? I don't have an example as such since the one I am working on is a homework question. Regards, darkie15

    Read the article

  • question with its query

    - by user329820
    Hi this is my homework and the question is this: List the average balance of customers by city and short zip code (the first five digits of thezip code). Only include customers residing in Washington State (‘WA’). also the Customer table has 5 columns(Name,Family,CustZip,CustCity,CustAVGBal) I wrote the query like below is this correct? SELECT CustCity,LEFT(CustZip,5) AS NewCustZip,CustAVGBal FROM Customer WHERE CustCity = 'WA' THANKS!!

    Read the article

  • Lisp: Determine if a list contains a predicate

    - by justkt
    As part of a homework assignment in Lisp, I am to use apply or funcall on any predicates I find. My question (uncovered in the coursework) is: how do I know when I've found a predicate in my list of arguments? I've done some basic google searching and come up with nothing so far. We're allowed to use Lisp references for the assignment - even a pointer to a good online resource (and perhaps a specific page within one) would be great!

    Read the article

  • Kernel error causing cpu to go into shutdown state

    - by EpsilonVector
    What kind of Kernel error can cause the cpu to go into a shut down state? I'm doing a homework assignment in OS, and we did changes in sched.c (adding a new scheduling policy, which involved ading another prio_array to the queue and switching between them when needed). Processes using this policy cause the cpu to enter a shut down state when they finish. Any suggestions where to look?

    Read the article

  • JAVA: Can't get context parameters in Filter

    - by DaTval
    Hello, I have a filter and parameters in web.xml web.xml is like this: <filter> <description> </description> <display-name>AllClassFilter</display-name> <filter-name>AllClassFilter</filter-name> <filter-class>com.datval.homework.AllClassFilter</filter-class> <init-param> <param-name>DB_URL</param-name> <param-value>jdbc:derby:C:/Users/admin/workspace/homework03/homework/databases/StudentsDB;create=true</param-value> </init-param> <init-param> <param-name>DB_DIALECT</param-name> <param-value>org.hibernate.dialect.DerbyDialect</param-value> </init-param> <init-param> <param-name>DB_DRIVER</param-name> <param-value>org.apache.derby.jdbc.EmbeddedDriver</param-value> </init-param> </filter> mapping is working well. But I can't get this parameters in my filter. public void init(FilterConfig config) throws ServletException { // TODO Auto-generated method stub debugMessage = config.getInitParameter("debugMessage"); ctx = config.getServletContext(); } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // TODO Auto-generated method stub // place your code here ctx.log("Start - " + debugMessage); String myDbUrl = ctx.getInitParameter("DB_URL"); String DB_DIALECT = ctx.getInitParameter("DB_DIALECT"); String DB_DRIVER = ctx.getInitParameter("DB_DRIVER"); Map<String,String> pr = new HashMap<String,String>(); pr.put("hibernate.connection.url", myDbUrl); pr.put("hibernate.dialect", DB_DIALECT); pr.put("hibernate.connection.driver_class", DB_DRIVER); EntityManagerFactory emf = Persistence.createEntityManagerFactory("students",pr); EntityManager em = emf.createEntityManager(); request.setAttribute("em", em); chain.doFilter(request, response); em.close(); ctx.log("end - " + debugMessage); } I have checked and myDbUrl is null. What I'm doing wrong? Any idea? Sorry about code, I will change it later :)

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >