ScottieF 18 Newbie Poster

Ahh I ya actually the date is instead of weeks broken into days is a way better idea.

So I'd have a table that has an employee, the job he is at, a date, and the hours they worked that day.

Like this?

Employee | Job | date | hours
John Doe Job A 10-05-15 10
John Doe Job A 10-06-15 10
John Doe Job A 10-07-15 8.5
John Doe Job A 10-08-15 8
John Doe Job A 10-09-15 9
John Doe Job B 10-12-15 8.5
John Doe Job B 10-13-15 8
John Doe Job C 10-14-15 9
John Doe Job C 10-15-15 9
John Doe Job C 10-16-15 9

It seem a little weird to me to have so many rows being created with the same Employee and Job columns but I can't think of any other way to store them in a database. And I know my project isnt that big but for huge projects with a method similar to this it looks like it could be creating an insanely huge number of rows every day. Is mySQL extrememly fast at pulling out data from billiions or possibly even trillions of entries and is this the right way to tackle a problem like this?

ScottieF 18 Newbie Poster

Bold Text HereHi there I'm just wondering what the best or a good table layout would be for a little project I'm trying to do at work. I work at a temp to perm agency where companies use us for the probationary peroid of employement and then hire the workers on once they have completed the necessary amount of hours at their facility. So I'm trying to set up an online application signup and management system for our jobs and employees.

So basically we have many employees and many jobs and I'd like to store information about each employee and then create jobs that I can assign to them. The part I'm having diffictulty figuring out the best layout for is keeping track of their hours. So once I have an employee and a job set up I want the employee to be able to be assigned to that jobs and each week keep track of their hours for that job. Sometimes an employee may not workout at a certain location so they get moved to another job mid week and will have essentially have two jobs for that one week.

I was thinking about having an employee table, a job table, and then a employee_job table that has a foreign key to an employee and a job. In the employee_job table there would be a one to many link with a weeks table which would just hold how many hours the employee worked that week for that specific job. …

ScottieF 18 Newbie Poster

This does something similar to what you want. Try to read each line and understand them they are pretty easy to follow.

print "Enter 5 numbers: "

numbers = []
for i in range(5):
    numbers.append(int(raw_input("Enter number " + str(i + 1) + ": ")))

print "The lowest number is " + str(min(numbers))
print "The highest number is " + str(max(numbers))
print "The sum the numbers is " + str(sum(numbers))
print "The average the numbers is " + str(sum(numbers)/len(numbers))
ScottieF 18 Newbie Poster
  1. You haven't said what your question is. I can guess that you just want someone to take your source and fix it so that it does your circular shift on the numbers. But it would be nice to hear what you think is wrong first.

  2. Is this supposed to be a C++ problem because you can't pass by reference like how you have in C.

ScottieF 18 Newbie Poster

I'm pretty sure you want to create a custom context processor. It will add all the key/values you create in it to the dictionary that is used to fill in the variables that you have in your templates.

A quick search gives this example which looks pretty good
http://bradmontgomery.blogspot.ca/2009/01/add-context-processor-for-your-django.html

ScottieF 18 Newbie Poster

If you take humanChoice out of main then it will never know what the human variable is in main for the check:

if (human == 'Q' || human == 'q') break;

so it will never exit when you press Q or q. And if you take humanChoice out of printScore it will not know what the human variable is in printScore() unless you pass it in to the print score function like printScore(human).

So what I would change is:

void printScore()

to

void printScore(char human)

remove

char human;

and

human = humanChoice();

from the print score function

re add

human = humanChoice();

to your main() and then change your printScore function call to pass in the human variable from main like this

printScore(human);

Here is the full source code with changes and a few comment lines above the changed lines to show you where things were edited:

#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;

int computerChoice()
{
    int compChoice = rand() % 3;
    return compChoice;
}

char humanChoice()
{
    char choice;

    while(true)
    {
        // prompt for, and read, the human's choice
        cout << "Choose(Rock,Paper,Scissors,or Quit): ";
        cin >> choice;
        cin.ignore(1000, 10);

        // if human wants to quit, break out of loop
        if (choice == 'Q' || 'q') break;
        if (choice == 'R' || choice == 'r') break;
        if (choice == 'S' || choice == 's') break;
        if (choice == 'P' || choice ==
sfuo commented: gj bro +8
ScottieF 18 Newbie Poster

Should be like pyTony says call sound.play(rem_vocals(sound)) because your rem_vocals function is returning the new__song. But are you sure your error is not from import sound. I don't see any module that exists with that name unless you have made it yourself.

sfuo commented: gj +8
ScottieF 18 Newbie Poster

You just have to manually increase i at the end of the loop. And for the for loop you don't have to have i = 0 above it, just say for i in range(len(s)):

s = raw_input("Enter a string: ")
a, i = 0, 0
while i < len(str(s)):
    if s[i] == ' ':
        a += 1
        print str(a) + '. ' + 'There was a space in position ' + str(i) + '.'
    i += 1
ScottieF 18 Newbie Poster

Your first problem is you didn't pass your variables row and column into your display_table() like display_table(row, column). Your next issue is in your loops but you will see that when you pass the variables to the function. Also the problem suggests using string formatting to position the text not using '\t's for tabbing.


I can show you what I got using python 3.2, I see you are still using a python 2.x version so this won't work without changes for you.

#Multiplication Table

def get_integers():
    rows = input("Enter a number for the rows: ")           #get rows
    columns = input("Enter a number for the columns: ")     #get columns
    display_table(rows, columns)                            #pass rows and columns to display_table
    
def display_table(rows, columns):
    rows = int(rows)                                        #convert rows to an int
    columns = int(columns)+1                                #convert columns to an int but increase by 1 because loops don't include the last nubmer
    length = 5*(columns-rows+1)                             #length is the number of '-'s used when making a dashed line between rows the + 1 is because of the far left column
    
    
    #print the first row (the one with no multiplication occurring)
    print("{:>4}|".format(""), end="")
    for column in range(rows, columns):
        print("{:>5}".format(str(column)), end="")
    print()
    
    #print the remaining rows
    for row in range(rows, columns):
        print("-"*length)                                   #print a line of dashes '-'
        print("{:>4}|".format(row), end="")                 #print the first number (the one not being multiplied)
        for column in range(rows, columns):
            print("{:>5}".format(row*column), end="")       #loop through the columns and multiple it by the the current row
        print()                                             #finally print a newline
    print()
    
    
    
#the …
ScottieF 18 Newbie Poster

Ya but if you look at what the OP posted as input

And this is what I get back
what die would you like to use: d100

he uses the d, but if he wanted he could rip the number off the end of it and then do what you suggested which is probably an upgrade to what he has. But I think it is a beginner programming class and they might not have learned all that stuff yet.

ScottieF 18 Newbie Poster

I think you have your ""'s backwards on your if statement and print statement

I'll walk you through d4 for example
so the program asks the user what die they want - lets say they type "d4"
then the program randomly generates a value for the variable d4 you have - lets say it generates 3
now the if statement checks to see if choice which is a string of "d4" is equal to the integer stored in d4 which is 3

so it will not go into the if statement because "d4" != 3

what I think you want is to just reverse the quotes on your print and if statement for the d4 and all the other dx's

so that it is like this

if choice == "d4":
     print d4

this will check to see if they typed in "d4" and will print the random value that you generated

ScottieF 18 Newbie Poster
#include <cstdlib>
#include <iostream>

using namespace std;

// The function checkQuestion is being overloaded
// Overloading a function means having the same function name
// but multiple definitions with different parameter types exist
// so here there is basically an int, string and bool version 
// of checkQuestion
void checkQuestion(int intAnswer, string result[]);
void checkQuestion(string stringAnswer, string result[]);
void checkQuestion(bool boolAnswer, string result[]);

int main(int argc, char *argv[])
{
    int intAnswer = 3;
    string stringAnswer = "Abraham Lincoln";
    bool boolAnswer = true;
    string result[]={"correct", "incorrect"};
    
    // Call the 3 different functions using the above variables
    // Note: the result argument can be removed and simplely just
    // replace the cout << result in the functions with
    // either cout << "correct"; or cout << "incorrect"; 
    checkQuestion(intAnswer, result);
    checkQuestion(stringAnswer, result);
    checkQuestion(boolAnswer, result);



system("PAUSE");
return EXIT_SUCCESS;
}

void checkQuestion (int intAnswer, string result[]){
    cout << "This intAnswer answer is ";

    if (intAnswer == 3)    
         cout << result[0];
    else
        cout << result[1];

    cout << endl;
}   
void checkQuestion (string stringAnswer, string result[]){
    cout << "This stringAnswer answer is ";

    if (stringAnswer == "Abrahim Lincoln")
         cout << result[0];
    else
        cout << result[1];

    cout << endl;
}   

void checkQuestion (bool boolAnswer, string result[]){
    cout << "This boolAnswer answer is ";

    if (boolAnswer == true)  
         cout << result[0];
    else
        cout << result[1];

    cout << endl;
}

There ya go bud hope you understand what function overloading is now. well cyaz.

ScottieF 18 Newbie Poster

Ya when you use cin >> it leaves a '/n' in the buffer for some reason so you need to use cin.ignore() to get rid of that otherwise it will carry that over to your cin.getline() and will just use the '/n' making it do nothing like you say. BUT if you just stick cin.ignore() after your cin >>'s and when it asks you if you want to run one more time and you type something like "yes" then it will get rid of the 'e' and use the 's' in the buffer for your next word. Iono why it does that but to prevent it I would probably try creating a check to make sure the user only entered in 'y' or 'n' like 1 char not a string.

GL HF

richman0829 commented: Very helpful +1
ScottieF 18 Newbie Poster

Oh now I see what that does thanks jonsca that makes more sense now lol. I have a new question now though.

For this piece of code:

double  one_zero;
	*(a+1)[0] = one_zero;
	double one_one;
	*(a+1)[1] = one_one;
	double one_two;
	*(a+1)[2] = one_two;

can you have *(a+1) like this or do you to do something like this:

double  one_zero;
	*(a+sizeof(double))[0] = one_zero;
	double one_one;
	*(a+sizeof(double))[1] = one_one;
	double one_two;
	*(a+sizeof(double))[2] = one_two;

because I thought that using the *(a) brings you to a's memory location so if you are going to move down to the next row of a multi dimensional array you would need to move down the size of a double not just 1. Unless putting 1 there does move it down based on type and I might be completely wrong.

hrmmmmmz actually now that I think about how I think the memory is set out for this I would think you would have to access it like this :

double  one_zero;
	*(a+3*sizeof(double))[0] = one_zero;
	double one_one;
	*(a+3*sizeof(double))[1] = one_one;
	double one_two;
	*(a+3*sizeof(double))[2] = one_two;

where you multiply the value of the double by 3 because there are 3 doubles before it from the first row of the array.

Thanks in advance for anyone that can help clear up what the +1 does if it is actually right.

ScottieF 18 Newbie Poster

man sorry to ask a question on your question forum but what does this do:

double zero_zero;
	*(a+0)[0] = zero_zero;
	double zero_one;
	*(a+0)[1] = zero_one;
	double zero_two;
	*(a+0)[2] = zero_two;

question 1:
what is *(a+0)[0] supposed to be?
do you mean a[0][0]?
question 2:
why are you setting this *(a+0)[0] = zero_zero;
when zero_zero was just declared and has no value attached to it?

if I knew what that ment I could understand your code probably 100x better than I do right now. Thanks cya.

ScottieF 18 Newbie Poster

okie dokie I just did this program and I'll tell you a little bit about the code to get you started. I can't really give you the sudo code because then it would be ultra obvious and easy for you to copy lol. But if you can show some progress with what I give you here I'll give you more help if you need. OK HERE WE GO:

I used 3 for variables i, j, and k
I used 3 for loops in this format
for(i = 1; i <= 10; i++){
for()
//one additional line of code here out side of the 2 inner for loops
for()
cout << endl;
}

So the first for() that encapsulates the other 2 runs 10 times and goes from 1-10 (if you notice you will see that the left hand side of the numbers go from 1 down to 10 [the last number is 0 which here is a big hint is 10%10 so all of your cout << statements should have %10 on them so that none of the numbers are bigger than 10])

2nd to last hint is the first inner for loop gives the first half of the numbers in each the line. The mystery comment line I put in between the 2 loops is the center number and the last loop is the other half of the values.

last hint which is pretty jumbo is you will …

ScottieF 18 Newbie Poster

Wow that is one crazy problem and and be probably interpreted a few different ways.

The way I read it is
1) get 4 expense values from the user ( because they have 4 games a year)

2) get the average of the 4 expenses ( so add the for values you got and divide by 4)

3) write the 4 expenses into a text file Expenses.txt ( basically a test to see if you can write to a file)

4) copy the data in that text file you just wrote into another text file Expenses2.txt ( basically a test to see if you can copy from a file )

5) check to see the % of the average of expenses typed by the user in comparison to the money given for 1 game. (so 50,000/(average expense)

6) then use that % and print to the console:
1. If the expenses greater than 80% show as” Very Expensive”.
2. If the expenses are greater than 60% and less than 80% than show “Expensive ”
3. If the expenses are greater than 50% and less than 60% than show “Less Expensive ”
4. If the expenses are greater than 40% and less than 50% than show “Not Costly”.
5. If the expenses are less than 40% than show “Best”.

Depending on the % you got

That's what I got from reading the problem, but I would double …

ScottieF 18 Newbie Poster

I suppose using a multidimensional array would simplify the sorting process, I'm just unsure of how to use them. Any suggestions? It only needs to be sorted through item number, then printed with the corresponding item name. Thanks for taking the time to help.

I just realised that the 2 data types are different so using a multi dimensional array won't work. However if you make a struct with the datatypes int and string. Then use a one dimensional array and store the number in the int and the name in the string. Then when doing your sort you will do something like myArr[index].itemNumber to access the item number and sort the arrays using that value. Then when you have it sorted you just print it out running through the array using myArr[index].itemName

ScottieF 18 Newbie Poster
#include <iostream>
#include <vector>
#include <string>
using namespace std;


void printVector( vector<string> v )
{

  for(unsigned int i = 0; i < v.size(); i++)
  {
    cout << v[i];
  }
  cout << endl;

	return;
}


int main()
{
    int nStrings=0;
    
    string str="";
    
    vector<string> myVector;
    
    char cAlphabet[] = {'a','b','c','d','e','f',
    		'g','h','i','j','k','l','m','n','o','p',
    		'q','r','s','t','u','v','w','x','y','z'};
    
    str=cAlphabet;
    cout<<str<<endl;
    
    cout<<"How many strings would you like?"<<endl;
    cin>>nStrings;

    int dist = 0;
    for(int i=0; i < nStrings; i++)
    {
    	static int j=0;
        // the %26 keeps j (the starting point of the substring)
        // within the bounds of the alpha bet
    	j = (j + i)%26;
        

        dist = i+1;
        // this checks to see if the distance from the starting point
        // overflows the alphabet limit
        // if it does it sets it so that the distance from j will hit
        // 25 so that the later overflow check can start from 0
        // which makes the loop from z being 25 and a being 0
        if(j + (i+1) > 26){
            dist = 26 - j;      
        }
        
        myVector.push_back(str.substr( j, dist ));

        // again checking for overflow but this time using the % operator on
        // the overflow to see how far it is going over
        // then just starting from 0 pushback that far.
        if(j + (i+1) > 26){
          int overflow = (j + (i+1))%26;

        // because the number of letters displayed is always going to be
        // (i+1) this while loop makes sure that for the cases when dist + overflow don't
        // add up to (i+1) another …
ScottieF 18 Newbie Poster

Can you post a sample input file so I can take a look?

Are the item numbers linked to the items names. So if you put them in a multi dimensional array you can just sort it using the item number, or does it need to be able to sort by item number AND alphabetically by the item name?


Thanks.

ScottieF 18 Newbie Poster
# include <iostream>
# include <string>
using namespace std;

// Protype for the avg function:
// Passing by reference mainAverage which is the average variable declared in 
// main the function can have a void return type and still get the average grade
// back into the main function because the value of mainAverage is directly changed
// in the avg().
void avg (double& average);

int main()
{
	// String variable for the student's name
	string name; 
	double mainAverage = 0;
	
	// Gets the name of the student
	cout << "Student name: ";
	getline(cin, name);
	
	// sends mainAverage into the avg()
	avg(mainAverage);
	
	
	cout << "The average grade for " << name << " is " << mainAverage << "."<<endl;
	
	system("PAUSE");
	return 0;
}

void avg (double& average)
{
	int grade[5];
	double sum = 0;
	
	// Extra space to make it look better
	cout << endl;
	
	// Loops through 5 times gathering a grade value and summing them all together
	for (int i=0; i<5; i++)
	{
		cout << "Please enter grade: ";
		cin >> grade[i];
		sum += grade[i];
	}
	cout << endl;
	
	// Caclulates the average after the loop is complete
	average = sum / 5;
}

You had a few problems so here is a short list of them:
1) Your name variable was declared as a single char and not a string. This is why if you gave a student name of anything more than 1 character you it would just flash the grade prompt but not …

new programer commented: Very clear help and care to deliver precise information .. all the best +1