David W's Profile User Rating: *****

Reputation: 275 Architect
Group:
Authors
Active Posts:
1,767 (0.87 per day)
Joined:
20-September 08
Profile Views:
20,190
Last Active:
User is offline Private
Currently:
Offline

Previous Fields

Country:
CA
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
Who Cares
Your Car:
Chevrolet
Dream Kudos:
1225

Latest Visitors

Icon   David W is off-line ...

Posts I've Made

  1. In Topic: circular link list problem

    Posted 26 Sep 2013

    Hi Annie,

    in reply to your above questions, please see the added comments in the code snippet below.

    Recall that in C++, 'friends' have access to 'private' data and methods of a class, and we here, in class Cll, want to give that class access to the private data in class Node.


    class Cll; // forward declaration ...
    
    class Node
    {
        friend class Cll; // Note the 'forward declaration' above, to permit giving ...
                         // class Cll 'friend' status here, since 'class Cll' is yet to be defined below
    private:
        int data;
        Node* nextptr;
    public:
        Node() : nextptr(0) {}
        
        Node( int val ) : data(val), nextptr(0) {}
     } ;
     
     
    class Cll //circular link list
    {
    private:
        Node* head;
        Node* tail;
    public:
    
    ...
    
    } ;
    
    
  2. In Topic: Random Number and Statement in Do While Loop looped twice

    Posted 26 Sep 2013

    Do you want the computer to find some user pre-input number?

    Or ...

    Do you want the user to input numbers ...
    to try to find the number the program has selected?
  3. In Topic: circular link list problem

    Posted 26 Sep 2013

    Try this in your print ,,,


        void print()
        {
            Node* tmp = head;
            if( tmp != 0 )
            {
                cout << "List items:";
                cout << ' ' << tmp->data;
                tmp = tmp->nextptr;
                while( tmp != head )
                {
                    cout << ' ' << tmp->data;
                    tmp = tmp->nextptr;
                }
            }
        }
    



    A little easier style of code (for me) to see ...

    #include <iostream>
    
    
    using namespace std;
    
    class Cll; // forward declaration ...
    
    class Node
    {
        friend class Cll;
    private:
        int data;
        Node* nextptr;
    public:
        Node() : nextptr(0) {}
        
        Node( int val ) : data(val), nextptr(0) {}
     } ;
     
     
    class Cll //circular link list
    {
    private:
        Node* head;
        Node* tail;
    public:
        Cll() : head(0), tail(0)  {}
        
        void insert( int val )
        {
            Node* newptr = new Node( val );
            if( head == 0 )
            {
                newptr->nextptr = newptr;
                head = newptr;
                tail = newptr;
            }
            else // push front ...
            {
                newptr->nextptr = head;
                tail->nextptr = newptr;
                head = newptr;
            }
        }
    
        void print()
        {
            Node* tmp = head;
            if( tmp != 0 )
            {
                cout << "List items:";
                cout << ' ' << tmp->data;
                tmp = tmp->nextptr;
                while( tmp != head )
                {
                    cout << ' ' << tmp->data;
                    tmp = tmp->nextptr;
                }
            }
        }
    } ;
     
     
     
    int main()
    {
        Cll obj;
    
        obj.insert(7);
        obj.insert(8);
        obj.insert(9);
        obj.print();
    
        cout << "\n\nPress 'Enter' to continue/exit ... ";
        cin.get();
        return 0;
    }
    
  4. In Topic: I need help with a task of writing a simple program.

    Posted 26 Sep 2013

    Typically the very first C++ program demo'd ...

    shows how to print a simple line of text on the console screen.

    The text printed out on the console screen is often just: "Hello World!"

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        cout << "Hello World!" << endl << endl;
    
        cout << "Press 'Enter' to continue/exit ... ";
        cin.get(); // keep 'Window' open until 'Enter' key is pressed ..
    }
    




    Then a next step could be to get some input from the user via the keyboard ...

    and to then print that input on the console screen.


    #include <iostream>
    #include <string>
    
    using namespace std;
    
    
    int main()
    {
        cout << "Please enter your name: ";
    
        string name; // get a string to hold some text ...
        cin >> name; // enter some text and see what happens
    
    
        cout << "Are you really: " << name << "?" << endl;
    
    
        // here we 'eat' the above left over '\n' char 
        // ( and any other left-over char's there )
    
        getline( cin, name );
    
        cout << "Please enter your WHOLE name: ";
        getline( cin, name ); // all your names and see what happens
    
        cout << "Are you really: " << name << "?" << endl;
    
        cout << "Press 'Enter' to continue/exit ... ";
        cin.get(); // keep 'Window' open until 'Enter' key is pressed ...
    }
    




    Then a next (BIG) step might be like 'your problem' ...

    that combines getting input IN A LOOP (using a 'while loop' )

    testing the input using an 'if' statement ...

    to do some data processing on each item of data that was input ...

    This may help you to get started ...

    Enjoy!


    // takeIn10Nums.cpp //
    
    /*
    	I have to write a program that takes in ten numbers ...
    	
    	 * then outputs the sum of the negative numbers, 
    	 * the sum of the positive numbers 
    	 * and then the sum of all the numbers ...
    
    */
    
    #include <iostream> // so you can use the C++ library cin, cout, etc...
    
    using namespace std; // so we can code 'cout' instead of 'std::cout' ... etc
    
    
    int main() // all C++ programs have a 'main; function where the program starts
    {
        // declare some variables that we need ...
    	int sumPos = 0; // MUST set sums ro zero to start the summing
    	int sumNeg = 0; // MUST set sums ro zero to start the summing
    	int tmp ;
    	
    	cout << "We are now going to loop to get 10 integers ...\n\n";
    	
    	int i = 0; // set counter to initial value of zero ...
    	while( i < 10 ) // check value of counter at top of WHILE LOOP ...
    	{
    		cout << "Please input number " << i+1 << " : ";
    		cin >> tmp;
    		if( cin.good() )
    		{
    			if( tmp >= 0 ) sumPos = sumPos + tmp; // since num was pos ...
    			else sumNeg = sumNeg + tmp;
    			++i; // ok, we have a good value, so increment counter
    		}
    		else // Oops ... some bad data was entered above, so ...
    		{
    			cin.clear(); // clear any/all cin error flags set above
    			cout << "\nNOT valid integer input ... try again please.\n";
    		}
    		
    		cin.sync(); // 'keeping cin stream flushed as we go' ... 
    		
    	} // end of WHILE LOOP ...
    	
    	
    	
    	// when reach here, we had 10 valid numbers,
        // so print out the results ...
        
        cout << endl; // prints a blank line
    	
    	cout << "The sum of all the positive numbers was: " << sumPos << endl;
    	cout << "The sum of all the negative numbers was: " << sumNeg << endl;
    	cout << "The grand sum of all the numbers was: " << sumPos + sumNeg << endl;
    	
    	cout << "\nPress 'Enter' to continue/exit ... ";
    	cin.get(); // Keep Window open by waiting for 'Enter key' to be pressed ... 
    }
    
    
  5. In Topic: basic c if else problems

    Posted 25 Sep 2013

    View Postslaveforthewave, on 25 September 2013 - 11:22 AM, said:

    yes, it isn't printing the data at the end like it is supposed to.


    I think you meant to say: "like it was hoped to do."

    Think about your design ...

    You have 3 levels of 'if's to get past to get any good output ... (you first need to validate 3 user inputs)

    Since you haven't yet used functions to make your coding much easier by breaking up each 'job' up into its own function

    (a function is a named and called block of code that can receive input and pass back output)

    you can code each block, repeatedly, as needed.

    Here is a suggested outline:

    #include <stdio.h>
    #include <stdlib.h>
    
    
    /* global defines ... */
    /* so can easily change values at top here to what-ever you need */
    
    
    #define MAX_HRS 72		/* max permitted working hours in a week */
    #define MIN_RATE 10.1	/* hourly pay rate */
    #define MAX_RATE 30.3
    #define MIN_SAL 50.5	/* in thousands per year */
    #define MAX_SAL 150.15	/* in thousands per year */
    #define OT_FACTOR 1.75
    
    
    
    int main()
    {
        while( 1 ) /* 'main' loop ... loop forever until 'break' ... */
        {
            
            /* first INNER input loop to get Emplyee TYPE (or quit) */
            
            /* Note: scanf 'error value' will be 0 and 'out of valid range' */
            int typeEmp = 0; 
            while( 1 )
            {
                printf( "Input 1 for hourly employee or 2"
                        " for salaried employee (or 3 to quit): " );
                scanf( "%d", &typeEmp );
                /*
                    Note: all char's entered above,
                          after any valid leading 'int' char's,
                          (like the trailing '\n' char),
                          are STILL in the stdin buffer ...
                */
    
                /* keeping stdin flushed 'as we go' */
                while( getchar() != '\n' ) ; /* flush stdin ... */
                
                if( typeEmp >= 1 && typeEmp <= 3 ) break; /* out of INNER loop since have good input */
                /* else ... print error message ... */
                printf( "\nValid input here are numbers in range [1..3]\n\n" );
            }
            
            if( typeEmp == 3 ) break; /* 'quit' was requested above... */
            
            
            
            /* Ok ... we have a valid typeEmp 1 or 2 */
            
            if( typeEmp == 1 )
            {
                /* loop to get valid hourly rate */
                /* loop to get valid hours this week */
            }
            else /* must be typeEmp 2 */
            {
                /* loop to get valid yearly rate (in k units per year) */
                /* loop to get valid hours this week */
            }
            
            
            /* Ok ... we have valid rates and hours ... */
            
            if( typeEmp == 1 )
            {
                /* cal and show data and weeks pay */
            }
            else /* must be typeEmp 2 */
            {
                /* cal and show data and weeks pay */
            }
             
            puts( "\nOk ... here we go again for "
                  "a possible next employee ...\n" );
        }
     
        printf( "\nPress 'Enter' to continue/exit ... " );
        fflush( stdout );
        return  0;
    }
    



    You might like to compare the above design with the below succession of nested if's ...
    ( where any input error has the user 'starting over from the top' ... )


    #include <stdio.h>
    #include <stdlib.h>
    
    /*
        Note 0: in this incomplete example, a 'salaried emplyee' is paid
                his 'basic week' = salary * 1000 / 52
                even if hours-worked were zero that week
        Note 2: that (yearly) salary is entered in 'k' units
        Note 3: 'our salaried employee' overtime begins after 60 hrs/wk
        Note 4: for efficent running code,
                most probable cases are handled firstly ...
    */
    
    /* global defines ... */
    /* so can easily change values at top here to what-ever you need */
    
    
    #define MAX_HRS 72		/* max permitted working hours in a week */
    #define MIN_RATE 10.1	/* hourly pay rate */
    #define MAX_RATE 30.3
    #define MIN_SAL 50.5	/* in thousands per year */
    #define MAX_SAL 150.15	/* in thousands per year */
    #define OT_FACTOR 1.75
    
    
    
    int main()
    {
        while( 1 ) /* loop forever until 'break' ... */
        {
            int typeEmp = 0; /* scanf 'error value' will be this '0' */
    
            printf( "Input 1 for hourly employee or 2"
                    " for salaried employee (or 3 to quit): " );
            scanf( "%d", &typeEmp );
    
            /* keeping stdin flushed 'as we go' */
            while( getchar() != '\n' ) ; /* flush stdin ... */
            
            
            if( typeEmp == 3 ) break; /* 'quit' was requested ... */
    
    
            if( typeEmp == 1 ) /* '1' is for 'hourly employee' */
            {
                
                
                /* your code goes here ...*/
                printf( "\nNot coded yet ... \n" );
    
    
            }
            else if( typeEmp == 2 )
            {
                /* scanf 'error value' will be this -1 ... */
                int hrsWorked = -1;
                
                /*
                    NOTE below:
                    IF a decimal number is entered,
                    ONLY the 'int' part is accepted ...
                         i.e. decimal part is dropped
                */
    
                printf( "Enter WHOLE number of hours worked between 0"
                        " and %d, (salaried employee): ", MAX_HRS );
                scanf( "%d", &hrsWorked );
                while( getchar() != '\n' ) ; /* flush stdin ... */
    
                if( hrsWorked >= 0 && hrsWorked <= MAX_HRS )
                {
                    /* scanf 'error value' will be this 0.0 ... */
                    double salaryWage = 0.0;
                    double weeksPay = 0.0;
    
                    printf( "Enter salary wage (%.3f..%.3f)(k): ",
                            MIN_SAL, MAX_SAL );
                    scanf( "%lf", &salaryWage );
                    while( getchar() != '\n' ) ; /* flush stdin ... */
    
                    if( salaryWage >= MIN_SAL && salaryWage <= MAX_SAL )
                    {
                        printf( "\nYou are a salaried employee. \n" );
                        printf( "Your base yearly wage is: %.0f \n",
                                salaryWage*1000 );
                        printf( "Total hours worked this week: %d \n",
                                hrsWorked );
    
                        if( hrsWorked > 60 )
                        {
                            int hrsOvertime = hrsWorked-60;
                            double basePay = salaryWage * 1000/52;
                            weeksPay = basePay +
                                       hrsOvertime*basePay/60 * OT_FACTOR;
    
                            printf( "Overtime hours this week: %d \n",
                                    hrsOvertime );
                        }
                        else
                        {
                            weeksPay = salaryWage * 1000/52;
                        }
    
                        printf( "Pay this week: %.2f \n\n", weeksPay );
                    }
                    else
                        printf( "\nRestarting ...\n"
                                "Be more careful here to enter a number "
                                "between %.3f and %.3f (k).\n\n",
                                MIN_SAL, MAX_SAL );
                }
                else 
    				printf( "\nRestarting ...\n"
    						"Be more careful here to enter a number "
    						"between %d and %d.\n\n", 0, MAX_HRS );
            }
            else
                printf( "\nRestarting ... "
                        "invalid 'type of employee' was entered ...\n\n" );
        }
        
        printf( "\nPress 'Enter' to continue/exit ... " );
        fflush( stdout );
        return  0;
    }
    
    
    

My Information

Member Title:
DIC supporter
Age:
66 years old
Birthday:
June 29, 1947
Gender:
Location:
Toronto Ontario Canada
Interests:
The events that lead up to the soon return of Yeshua (Jesus) ... and being ready
Full Name:
David Wayne Zavitz
Programming Languages:
Basic
6502 Assembly
Comal
C++
HLA (High Level Assembly)
Pascal
C
Python
Sqlite3

Comments

Page 1 of 1
  1. Photo

    Invincible-99 Icon

    29 Jun 2012 - 06:10
    Oh, sorry!
    That link doesn't work.
    http://i48.tinypic.com/34qqrg3.jpg
  2. Photo

    Invincible-99 Icon

    29 Jun 2012 - 06:06
    Hi!
    [IMG]http://i48.tinypic.com/34qqrg3.jpg[/IMG]
  3. Photo

    Anarion Icon

    24 Jun 2012 - 13:44
    Regards to you, awesome friend! ;)
  4. Photo

    v0rtex Icon

    07 Jun 2012 - 03:04
    Thanks for the link! Why would u advise I look at HLA?
  5. Photo

    caleb123 Icon

    22 Jun 2010 - 19:37
    Would you like to be my website designing buddy? If you do, you can email me at cheryman22@yahoo.com
    You and I can give each other tips and answer question to make us both better at designing websites.
  6. Photo

    skyhawk133 Icon

    08 Jun 2010 - 09:43
    Great to have you David! Thanks for the kind comment.
  7. Photo

    xxxpriya Icon

    20 Feb 2010 - 21:25
    thanx a lot david
Page 1 of 1