User Profile

Collapse

Profile Sidebar

Collapse
midknight5
midknight5
Last Activity: Dec 1 '07, 05:10 AM
Joined: Oct 2 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • When you say add another possiblity do you mean add something like:

    if(a[j].getSpecies() > a[j+1].getSpecies() || a[j].calculateCost( ) > a[j+1].calculateCost( ))

    or add another if statement?...
    See more | Go to post

    Leave a comment:


  • Ok, ive made some progress and im down to my last two problems. First off, after ive opened up the file and sorted my trees by Species, I want to sort them ALSO by cost. but I am unsure of how to do that.

    Current bubblesort for species:

    Code:
    void bubblesort ( ChristmasTree a[],int n) // n = SIZE;
    {
         bool sorted = false;
         for (int i = 0; i < n-1 && !sorted; i++)
         {
    ...
    See more | Go to post

    Leave a comment:


  • Im so sorry but some of that I dont understand, im only in Intro to C++ and we are at the final stage of our learning for the semester so vectors and the like I havnt gotton to yet. I did however find a way that it will work but I encounter a problem that maybe someone can help me with. The point of this program is to open up a file with an unknown number of Tree[]s in it then read the lines and put the correct data into the correct part in the array...
    See more | Go to post

    Leave a comment:


  • Im afraid that may be too difficult for my experience with C++. Anyway this is what im up to:

    Code:
    void bubblesort (??? a[], int n); // Prototype
    
    void bubblesort (Tree[], int n) // n = SIZE;
    {
         bool sorted = false;
         for (int i = 0; i < n-1 && !sorted; i++)
         {
             sorted = true;
             for (int j = 0; j < (n-1-i); j++)
             {
    ...
    See more | Go to post

    Leave a comment:


  • I havnt worked with templates so im a bit confused. Would it look something like this?

    template <class Tree>
    void bubble_sort(Tre e[], int size);...
    See more | Go to post

    Leave a comment:


  • I had an idea. I have a function called getSpecies() and getCost() which simply returns the values found in whatever array area your in. Could I...

    Code:
    void bubblesort (char a[], int n) // n = SIZE;
    {
         bool sorted = false;
         for (int i = 0; i < n-1 && !sorted; i++)
         {
             sorted = true;
             for (int j = 0; j < (n-1-i); j++)
             {
    ...
    See more | Go to post

    Leave a comment:


  • midknight5
    started a topic Bubble Sort with an array filled with classes.
    in C

    Bubble Sort with an array filled with classes.

    Hello everyone, I am familiar with a normal bubble sort when dealing with an array of number but I am unsure as how to implement a sort when I have an array that is filled with classes which hold multiple values.

    I need to make a bubble sort that reaches into an array called Tree[100] which has in each storage location a class called Christmas Tree which have the values Species, Height, trunkDiameter, and costPerFoot. The sort will...
    See more | Go to post

  • midknight5
    started a topic Writing a Test Harness for a Function
    in C

    Writing a Test Harness for a Function

    Hey guys, ive created this time abunch of functions that I wish to test, so I want to create a driver that is easy to know if the functions work or not without cout-ing the results and then checking. Kinda like a pass-fail system I guess.

    so here is the function I want need to test.

    Code:
    int max(int a, int b)
    {
           if (a < b)
           {
                 a = b;
           }
     
     return
    ...
    See more | Go to post
    Last edited by midknight5; Nov 1 '07, 11:28 PM. Reason: Update

  • midknight5
    started a topic Creating my own functions.
    in C

    Creating my own functions.

    Hey guys, as I progress through my C++ education ive started getting into headers and drivers, so I figured for good practice I would make my own header file that contains function prototypes and a implementation file for testing.

    I want to make my own version of pow, so ive made a functions called:
    double power(double x, double y);

    Now we all know how a power works, its multiplies number x by itself y number...
    See more | Go to post

  • midknight5
    replied to Comparing Help!
    in C
    I actually tried something like that but received an error about conversion or the like, my proffessor said that it wasnt a good way to try and solve the problem so I just threw it out....
    See more | Go to post

    Leave a comment:


  • midknight5
    replied to Comparing Help!
    in C
    Oh man it worked! Im getting the correct information now! Thank you so much!
    See more | Go to post

    Leave a comment:


  • midknight5
    replied to Comparing Help!
    in C
    When you say returns the pointer to the first occurrence, does that mean no matter where it is in the file that the pointers moves back to that character unless it is not found?
    If so that isnt what I need because my program checks a multitude of tempuratures, and I just need to be able to check to see if the temp is - because if it is then I dont want to take count of it when determining the average of the tempuratures.

    Code:
    if(strchr(temp,
    ...
    See more | Go to post

    Leave a comment:


  • midknight5
    replied to Comparing Help!
    in C
    I dont think I did it correctly, sorry that website is a tad bit confusing to me. I've only been working with C++ for about two months now. (CompSci Freshman) Here is what I gathered though:

    (strchr(temp, '-' ))

    That says to check inside temp for a - right?
    See more | Go to post

    Leave a comment:


  • midknight5
    replied to Comparing Help!
    in C
    Im afraid im not familiar with that function, how does it work and what exactly does it do?
    See more | Go to post

    Leave a comment:


  • midknight5
    started a topic Comparing Help!
    in C

    Comparing Help!

    I am writing a program to where after a file is open, a temperature is put into a variable char temp[4000]; wile the program continues I need to check to see if there is a - in temp so that when I have all the temperatures it wont count -. what would be a way for me to check to see if there is a - in temp.

    Attempted code:
    if(temp.c_str() = "-")

    If needed I can post the full code.
    See more | Go to post

  • Actually ive made some good progress, I noticed that error in the while loop and changed it, so now im working on the second portion and I get this error:

    ISO C++ forbids comparison between pointer and integer

    Code:
    if (!strcmp(city, cityname))
     {
      cout << "City Found" << endl;
      
      indata.close();
      indata.clear();
      
      indata.open("200001hourly.txt");
    ...
    See more | Go to post

    Leave a comment:


  • Ok, I fixed it to a point, it now successfully compiles but now it is staying in the do-while loop forever and im not sure why! It successfully places the id number that relates to a city in the variable number, and puts the proper name of the city in cityname, but it seems like they arent comparing correctly.

    Code:
    void cityreport()
    {
     char city[MAX], line[MAX], cityname[MAX];
     ifstream indata;
     int number;
    ...
    See more | Go to post

    Leave a comment:


  • I wish it were my choice to get rid of the quote in the code but it isnt, I did however get it work.

    Ok, now that I have the name of the city in cityname, I have to have the code repeat the process untill if finds a match, so I figured a do/while would be fine.

    Code:
    void cityreport()
    {
     char cityname[MAX], line[MAX];
     char city;
     int number;
     fstream indata;
     
     cout <<
    ...
    See more | Go to post
    Last edited by midknight5; Oct 23 '07, 08:47 PM. Reason: Update

    Leave a comment:


  • Program to open large text document and find a city name.

    This is my first program to take advantage of functions. For this program I am required to open up a text document called "station.tx t" which has numbers and names in various rows scattered about it. the user is allowed to input a name of a city and the program should look for the city throughout the entire file. Now since the text file has a header, I know that I must get rid of this header file to continue looking through the file. So...
    See more | Go to post
    Last edited by midknight5; Oct 23 '07, 12:10 AM. Reason: Update

  • Ok, I seem to have hit another wall. Randomly my professor decided to add a stipulation to the program.
    It needs to display error messages if there are no grades in each student's file or if the student doesn't have a file at all.

    Code:
         while ( student_roster >> last >> first >> middle )
         // While there is data in the roster to be put into the named variables
         // do this:
    {
    ...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...