Like Tree2Likes

my professior gave us an example program for a fiter.. but I can't get it to work...

This is a discussion on my professior gave us an example program for a fiter.. but I can't get it to work... within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Elysia Code: sum = sum + points [i]; mean = sum / datapts; Now, what the heck ...

  1. #16
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Quote Originally Posted by Elysia View Post
    Code:
        
    sum = sum + points [i];
    mean = sum / datapts;
    Now, what the heck do you think this part of your code does?
    ....
    It does some really cool stuff when datapts is zero.

  2. #17
    Registered User Cess's Avatar
    Join Date
    Sep 2011
    Posts
    55
    3. Evaluate !(1 && !(0 || 1)).

    A. True

    I don't understand why this is true......can someone please break it down and explain it to me? thanks
    ~Cess~
    AKA : total newbie
    ....and totally frustrated
    thanks for any help given.....
    I feel like I"m going to fail this class....blah!

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,920
    1 = true,
    0 = false

    ==> !(true && !(false || true))
    ==> !(true && !(true))
    ==> !(true && false)
    ==> !(false)
    ==> true
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    !(1 && !(0 || 1)).

    Remimber your order of operations.
    ( 0 || 1 ) = 1

    ! (1 && !(1))
    ! (1 && 0)
    ! (0)
    1
    Cess likes this.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  5. #20
    Registered User Cess's Avatar
    Join Date
    Sep 2011
    Posts
    55
    Oh ok ya so even though "that OR will be evaluated after AND. " you have to still follow order of operations 1st! ok that makes sense. thank you!


    (0||1) = true
    !(0||1) =false
    1 && 0 = false
    ! ( 1 && 0) = true
    ~Cess~
    AKA : total newbie
    ....and totally frustrated
    thanks for any help given.....
    I feel like I"m going to fail this class....blah!

  6. #21
    Registered User Cess's Avatar
    Join Date
    Sep 2011
    Posts
    55
    Ok still going over the C++ tutorial on lesson 3

    Code:
    #include <iostream> 
    using namespace std; // So the program can see cout and endl
    int main() {   // The loop goes while x < 10, and x increases by one every loop   
    for ( int x = 0; x < 10; x++ ) 
                {     // Keep in mind that the loop condition checks    
                       //  the conditional statement before it loops again.    
                      //  consequently, when x equals 10 the loop breaks.  
                     // x is updated before the condition is checked.      
             cout<< x <<endl;   }  
     cin.get();
     }

    What does the cin.get(); do? It doesn't explain it as far as I can see and when I used it in code blocks I didn't notice anything different then when I didn't use it.
    Last edited by Cess; 10-23-2011 at 12:02 PM.
    ~Cess~
    AKA : total newbie
    ....and totally frustrated
    thanks for any help given.....
    I feel like I"m going to fail this class....blah!

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,920
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User Cess's Avatar
    Join Date
    Sep 2011
    Posts
    55
    what does str[i] = str[i] - 'a' + 'A'; mean in the code below

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        cout << "Enter a character string: ";
        char str[20];
        cin >> str;
        for (int i=0; str[i]; i++)
        {
    
            if ((str[i] >= 'a')&& (str[i] <= 'z'))
                str[i] = str[i] - 'a' + 'A';
            else
            {
                if ((str[i] >= 'A')&& (str[i] <= 'Z'))
                    str[i] = str[i] + 'a' - 'A';
            }
        }
        cout << str << endl;
        return 0;
    }
    thanks I have an exam at 1pm so any help would be great... I have to write 2 programs with prototypes in a hour so ya thanks.
    ~Cess~
    AKA : total newbie
    ....and totally frustrated
    thanks for any help given.....
    I feel like I"m going to fail this class....blah!

  9. #24
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Characters are basically integers with limited ranges (0-255 for an 8-bit unsigned char as an example). You can therefore perform arithmetic on char data types of the sort you are seeing here. Imaging for a moment that str[i] contains the letter 'b'. Subtracting 'a' from 'b' results in a difference of 1. If we then add 'A' and 1 together what do you think the result is?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  10. #25
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Cess View Post
    what does str[i] = str[i] - 'a' + 'A'; mean in the code below
    Chars are stored as single bytes. A single 8-bit byte has 256 possibilities; ie, a numerical value from 0-255 (unsigned) or -128 to 127 signed. These correspond to the ASCII table:

    Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion

    So if you subtract 'a' (97) from a lowercase ASCII letter and then add 'A' (65) to it, it will be capitalized.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my teacher gave it to us....
    By jacek in forum C Programming
    Replies: 3
    Last Post: 01-11-2010, 12:17 PM
  2. Othello game, gave up debugging
    By Nutshell in forum Game Programming
    Replies: 31
    Last Post: 01-26-2003, 01:05 PM
  3. gave it shot...it gave me an error!
    By LonelyPlanderWa in forum C Programming
    Replies: 3
    Last Post: 07-12-2002, 02:26 AM
  4. Please Heelp me ... I gave up
    By NANO in forum C++ Programming
    Replies: 14
    Last Post: 04-21-2002, 09:14 PM
  5. I am confused with this code that somebody gave me
    By face_master in forum C++ Programming
    Replies: 14
    Last Post: 11-16-2001, 01:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21