Open Side Menu Go to the Top
Register
Programming homework and newbie help thread Programming homework and newbie help thread

09-06-2016 , 08:22 PM
Also getline doesn't take an integer parameter. What are you passing 15 in for?

ETA: OK I'm misremembering - there are 2 getline functions, one is a global function that takes an istream and the other is a member on istream.
Programming homework and newbie help thread Quote
09-07-2016 , 08:17 PM
Yes, the outer while loop was the problem. I realized it minutes after posting after looking at it for some time. Oops.
Programming homework and newbie help thread Quote
09-11-2016 , 10:12 AM
Question about formatting output. I have a program that is outputting data roughly as follows:

Smith, John $1000.00
Smith, Joan $900.00

I want it to look like this:

Smith, John $1000.00
Smith, Joan $ 900.00
Jones, Mike $ 50.00

Basically, I want the numbers to the right of the dollar sign to be right aligned. When I just add in cout << right that doesn't work.

Here's what the code looks like right now:

Code:
cout << fixed << setprecision(2);
			cout << setw(25);
			cout << left;
			cout << emp[z] << " $" << empData[z][2] << endl;
Programming homework and newbie help thread Quote
09-11-2016 , 11:48 AM
setw gets reset after outputting a stream. You need to put another one when outputting the next (right aligned) stream. Without it it has a width of 0 so alignment is irrelevant. It's the only formatter that isn't "sticky".
Programming homework and newbie help thread Quote
09-13-2016 , 02:20 AM
I'm a senior at uni in comp sci and im finally being forced to take this stupid electrical eng class that I put off as long as I could.

Anyway, my question is, how does the "not" work with hex .... holy **** I think I realized the answer mid sentence rofl. I was going to ask how do you "not" a hex number. The professor said in class that 0xFFFF0FFF ---not---> = 0x0000F000 and I was thinking, yeah you can turn F's into 0's but what about E's? Do those turn into 1's and D's turn into 2's? (I was doing distance from edge on the 0,1,2,...,D,E,F hex number line).

I think I found my own answer... the only way to do it is to convert to binary AND THEN do the flipping. It was a sh**ty coincidence that the F's and 0's appeared to be flipping when really the flipping was of 1's and 0's on a lower level which turned into F's and 0's on the higher hex level.

Okay new question, the processor we use in lab for this class is all based on 32 bits. So 0xF, for this processor, is 0x(7 zero's)F, for instance. This ****ed me for 3 hours when I was trying to do a "right rotation of bits" on 0x12345678, I didn't account for the leading 0's when I converted 0x12345678 to binary (needed to add 4 or 5 0's to the front before doing the right rotation). That being said, if I was asked on a test to find the "not" for the hex number 0x1F025ABC (and answer in hex), do I have to do hex->binary->flip 1's & 0's -> hex? This will take me 30 minutes, is there a shortcut?
Programming homework and newbie help thread Quote
09-13-2016 , 04:03 AM
On the topic of assembly code, what's the difference between .s and .as? I tried googling it but its the type of question google sucks at being a resource for.
Programming homework and newbie help thread Quote
09-13-2016 , 07:47 AM
Quote:
Originally Posted by Ryanb9
I'm a senior at uni in comp sci and im finally being forced to take this stupid electrical eng class that I put off as long as I could.

Anyway, my question is, how does the "not" work with hex .... holy **** I think I realized the answer mid sentence rofl. I was going to ask how do you "not" a hex number. The professor said in class that 0xFFFF0FFF ---not---> = 0x0000F000 and I was thinking, yeah you can turn F's into 0's but what about E's? Do those turn into 1's and D's turn into 2's? (I was doing distance from edge on the 0,1,2,...,D,E,F hex number line).

I think I found my own answer... the only way to do it is to convert to binary AND THEN do the flipping. It was a sh**ty coincidence that the F's and 0's appeared to be flipping when really the flipping was of 1's and 0's on a lower level which turned into F's and 0's on the higher hex level.

Okay new question, the processor we use in lab for this class is all based on 32 bits. So 0xF, for this processor, is 0x(7 zero's)F, for instance. This ****ed me for 3 hours when I was trying to do a "right rotation of bits" on 0x12345678, I didn't account for the leading 0's when I converted 0x12345678 to binary (needed to add 4 or 5 0's to the front before doing the right rotation). That being said, if I was asked on a test to find the "not" for the hex number 0x1F025ABC (and answer in hex), do I have to do hex->binary->flip 1's & 0's -> hex? This will take me 30 minutes, is there a shortcut?
Each hex digit is 4 binary digits so you should be able to convert in place or memorize the not operation on each hex value if you want

0 = 0000 NOT = 1111 = F
1 = 0001 NOT = 1110 = E
2 = 0010 NOT = 1101 = D
3 = 0011 NOT = 1100 = C
4 = 0100 NOT = 1011 = B
5 = 0101 NOT = 1010 = A
6 = 0110 NOT = 1001 = 9
7 = 0111 NOT = 1000 = 8
8 = 1000 NOT = 0111 = 7

So it looks like not does in fact follow the pattern you described earlier assuming all of my math is correct.
Programming homework and newbie help thread Quote
09-13-2016 , 08:27 AM
Quote:
Originally Posted by Ryanb9
On the topic of assembly code, what's the difference between .s and .as? I tried googling it but its the type of question google sucks at being a resource for.
Assuming you're using gcc:

https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html

Didn't find .as on there though.
Programming homework and newbie help thread Quote
09-13-2016 , 08:28 AM
There's not really any memorizing to do. X + NOTX = F (or 15 if you prefer)
Programming homework and newbie help thread Quote
09-13-2016 , 10:01 AM
Quote:
Originally Posted by Ryanb9
(I was doing distance from edge on the 0,1,2,...,D,E,F hex number line).
You were doing it correctly, you just didn't realize that in doing so they always added up to 15, so overlooked the arithmetic shortcut Rusty pointed out.
Programming homework and newbie help thread Quote
09-13-2016 , 10:09 AM
Quote:
Originally Posted by Ryanb9
On the topic of assembly code, what's the difference between .s and .as? I tried googling it but its the type of question google sucks at being a resource for.
Are you sure it's .as and not .asm? Usually it's just the extension a particular compiler likes to use. It's all assembly.
Programming homework and newbie help thread Quote
09-13-2016 , 09:12 PM
Quote:
Originally Posted by Ryanb9
I'm a senior at uni in comp sci and im finally being forced to take this stupid electrical eng class that I put off as long as I could.

Anyway, my question is, how does the "not" work with hex .... holy **** I think I realized the answer mid sentence rofl. I was going to ask how do you "not" a hex number. The professor said in class that 0xFFFF0FFF ---not---> = 0x0000F000 and I was thinking, yeah you can turn F's into 0's but what about E's? Do those turn into 1's and D's turn into 2's? (I was doing distance from edge on the 0,1,2,...,D,E,F hex number line).

I think I found my own answer... the only way to do it is to convert to binary AND THEN do the flipping. It was a sh**ty coincidence that the F's and 0's appeared to be flipping when really the flipping was of 1's and 0's on a lower level which turned into F's and 0's on the higher hex level.

Okay new question, the processor we use in lab for this class is all based on 32 bits. So 0xF, for this processor, is 0x(7 zero's)F, for instance. This ****ed me for 3 hours when I was trying to do a "right rotation of bits" on 0x12345678, I didn't account for the leading 0's when I converted 0x12345678 to binary (needed to add 4 or 5 0's to the front before doing the right rotation). That being said, if I was asked on a test to find the "not" for the hex number 0x1F025ABC (and answer in hex), do I have to do hex->binary->flip 1's & 0's -> hex? This will take me 30 minutes, is there a shortcut?
The NOT operation you are referring to is called a ones complement.

The easy way to take the ones complement(NOT) of
Ox1F025ABC

For each hex digit what value plus hex digit equals 0xF (15).

OxE0FDA543

Ox1F025ABC + 0xE0FDA543 = 0xFFFFFFFF

For 0xDA

0xFFFFFF25

On the .as & .s file extensions, they are both assembly language
Programming homework and newbie help thread Quote
09-22-2016 , 05:40 PM
I'm having a recurring problem w/ python tutor. When I copy and paste functions, I frequently (but not always) run the visualization execution and it will stop at the first line (naming/defining the function) and tell me "program terminated." This occurs w/ valid functions that run fine in python. I'm correctly inputting python 3.3 as the operative language.

Help?
Programming homework and newbie help thread Quote
09-26-2016 , 09:21 PM
Thanks.

Another question:

I want to send this: 1101 0011 0011 0101

Using hamming code (correct single bit errors, using the normal even parity) i have to add 5 check bits, right?

The check bits I found for 1,2,4,8, and 16 were 0,1,1,1,1 respectively. This is different from answer in back of book. I cant find an online hamming code generator that will solve this for me (the one that I found gives something different from me and different from back of book). What am I doing wrong?
Programming homework and newbie help thread Quote
09-26-2016 , 09:40 PM
In my book there is an algorithm that takes 4 bits as an input and has a 1 bit output. It says it is an "XOR sum." How do you do an xor sum?

edit: this is what it comes from, maybe I'm missing something obvious here...



edit2: is it just doing a mod 2 on the 3 or 4 inputs (3 on top, 4 on bottom)?

Last edited by Ryanb9; 09-26-2016 at 09:46 PM.
Programming homework and newbie help thread Quote
09-27-2016 , 12:40 AM
I've never done anything with programming before, but I downloaded R today and I'm having trouble importing an Excel file. I installed the package '*****lsx' but when I tried to use it I get the error:

Code:
> library(*****lsx)
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  there is no package called ‘Rcpp’
Error: package or namespace load failed for ‘*****lsx’
So I google that and find this solution on stack overflow (it's for a different package ('ggplot2') but seems like same type of problem): http://stackoverflow.com/questions/3...for-data-table

Anyway I tried the most-upvoted solution for ggplot2 and it downloaded a bunch of stuff on my PC but it still doesn't work when I try to use the library, same error.

tl;dr help me import Excel files into R please

lol, 2p2 censors the package o p e n x l s x is what the asteriks should be

Last edited by hellomynameis; 09-27-2016 at 12:42 AM. Reason: censor
Programming homework and newbie help thread Quote
09-27-2016 , 01:10 AM
Look in your \R\R-x.y.z\library\ directory. Does it contain a directory called Rcpp and are there a bunch of files in said directory?
Programming homework and newbie help thread Quote
09-27-2016 , 01:53 AM
Quote:
Originally Posted by ChrisV
Look in your \R\R-x.y.z\library\ directory. Does it contain a directory called Rcpp and are there a bunch of files in said directory?
It is not =o

Weird, I assumed the 2nd line of the stack overflow solution would fix that:

Code:
remove.packages(c("ggplot2", "data.table"))
install.packages('Rcpp', dependencies = TRUE)
install.packages('ggplot2', dependencies = TRUE)
install.packages('data.table', dependencies = TRUE)
Going back to when I tried to install the Rcpp part, here's what I got, I'm not sure what it means but I didn't realize it was an error:

Code:
install.packages('Rcpp', dependencies = TRUE)
Installing package into ‘C:/Users/Erik/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.cnr.berkeley.edu/bin/windows/contrib/3.3/Rcpp_0.12.7.zip'
Content type 'application/zip' length 3265307 bytes (3.1 MB)
downloaded 3.1 MB
Programming homework and newbie help thread Quote
09-27-2016 , 02:30 AM
This part of the third answer on your StackOverflow link seems relevant to your interests:

Quote:
However, while the above command successfully downloads Rcpp, for some reason, it fails to explode the ZIP file and install it in my R's library folder
Answers #3 and #4 have instructions for trying to get R to behave itself but I'd probably go with what the bottom answer suggests and just manually install the library:

Quote:
These steps work for me:

Download the Rcpp manually from WebSite (https://cran.r-project.org/web/packages/Rcpp/index.html)
unzip the folder/files to "Rcpp" folder
Locate the "library" folder under R install directory Ex: C:\R\R-3.3.1\library
Copy the "Rcpp" folder to Library folder.
It sounds like that's all you need to do for R to consider the library available. Can't personally confirm that as I've never used R.
Programming homework and newbie help thread Quote
09-27-2016 , 02:59 AM
Which link do I click on that page to do that? (serious question)
Programming homework and newbie help thread Quote
09-27-2016 , 03:04 AM
In my experience, XOR stands for Exclusive OR (meaning the standard OR logical operator with the proviso that if both items are TRUE it returns FALSE).

So I am guessing that XOR in binary returns 1 if exactly one input is 1 and 0 if both inputs are either one or zero.
Programming homework and newbie help thread Quote
09-27-2016 , 04:35 AM
Quote:
Originally Posted by hellomynameis
Which link do I click on that page to do that? (serious question)
One of the bolded assuming you're running Windows or OSX.

Quote:
Windows binaries: r-devel: Rcpp_0.12.7.zip, r-release: Rcpp_0.12.7.zip, r-oldrel: Rcpp_0.12.7.zip
OS X Mavericks binaries: r-release: Rcpp_0.12.7.tgz, r-oldrel: Rcpp_0.12.7.tgz
Programming homework and newbie help thread Quote
09-27-2016 , 10:37 AM
Quote:
Originally Posted by Ryanb9
In my book there is an algorithm that takes 4 bits as an input and has a 1 bit output. It says it is an "XOR sum." How do you do an xor sum?

edit: this is what it comes from, maybe I'm missing something obvious here...



edit2: is it just doing a mod 2 on the 3 or 4 inputs (3 on top, 4 on bottom)?
From what I can tell an XOR sum is just continuous XOR operations. The example in your book is confusing me though as I'm not sure how a single bit produces 2 output bits. I get that you XOR the input with the register values but after that I'm lost.


EDIT: I should note that this is one of the few times where Wikipedia articles are overly technical and have not provided insight for me.
Programming homework and newbie help thread Quote
09-27-2016 , 12:20 PM
Each output bit is an XOR sum of the input bit and the bits shifted out of different registers.

Output bit 1 is (in ^ S2 ^ S3 ^ S5 ^ S6)
Output bit 2 is (in ^ S1 ^ S2 ^ S3 ^ S6)

So for input 111, the outputs will be:

Shift in the 1st input bit (1)
output bit 1 = (1 ^ 0 ^ 0 ^ 0 ^ 0) = 1
output bit 2 = (1 ^ 0 ^ 0 ^ 0 ^ 0) = 1

Shift in the 2nd input bit (1)
output bit 1 = (1 ^ 0 ^ 0 ^ 0 ^ 0) = 1
output bit 2 = (1 ^ 1 ^ 0 ^ 0 ^ 0) = 0

Shift in the 3rd input bit (1)
output bit 1 = (1 ^ 1 ^ 0 ^ 0 ^ 0) = 0
output bit 2 = (1 ^ 1 ^ 1 ^ 0 ^ 0) = 1

What I don't like about the 3 outputs they give is that they don't indicate which bit is 1 and which is 2. But I can tell by the XOR sums that they are as I calculated above.
Programming homework and newbie help thread Quote
09-27-2016 , 12:26 PM
Quote:
Originally Posted by Lattimer
Each output bit is an XOR sum of the input bit and the bits shifted out of different registers.

Output bit 1 is (in ^ S2 ^ S3 ^ S5 ^ S6)
Output bit 2 is (in ^ S1 ^ S2 ^ S3 ^ S6)

So for input 111, the outputs will be:

Shift in the 1st input bit (1)
output bit 1 = (1 ^ 0 ^ 0 ^ 0 ^ 0) = 1
output bit 2 = (1 ^ 0 ^ 0 ^ 0 ^ 0) = 1

Shift in the 2nd input bit (1)
output bit 1 = (1 ^ 0 ^ 0 ^ 0 ^ 0) = 1
output bit 2 = (1 ^ 1 ^ 0 ^ 0 ^ 0) = 0

Shift in the 3rd input bit (1)
output bit 1 = (1 ^ 1 ^ 0 ^ 0 ^ 0) = 0
output bit 2 = (1 ^ 1 ^ 1 ^ 0 ^ 0) = 1

What I don't like about the 3 outputs they give is that they don't indicate which bit is 1 and which is 2. But I can tell by the XOR sums that they are as I calculated above.
Wow thanks. I suppose that diagram does show that but for the life of me could not come to that conclusion on my own haha. It was driving me nuts!
Programming homework and newbie help thread Quote

      
m