TheFeedingHand
Member
Nice, although, is OpenGL still relevant these days? (aside from mobile graphics programming)
Yes, it's still the standard on non-Windows platforms.Nice, although, is OpenGL still relevant these days? (aside from mobile graphics programming)
Nice, although, is OpenGL still relevant these days? (aside from mobile graphics programming)
unsigned short n1 = 0; //[X][X][X][X][X][X][X][X][0][0][0][0][0][0][0][0]
unsigned char n2 = 4; //[0][0][0][0][0][1][0][0]
// I have to set the "1 0 0" in n1 without touching the X values.
Right now I'm switch of all first 8 bits "off" and the doing "n1 = n1 | n2" ?
What's the best way of doing this? Thank you.
n1 = n1 | 0x0004;
Ooooh, bitwise logic. Always fun.I'm working on a low resorts system and I need to set bits individually in C.
So I have an unsigned short, and I need to manipulate ONLY the first 8 bits using a second number.
Right now I'm switch of all first 8 bits "off" and the doing "n1 = n1 | n2" ?
What's the best way of doing this? Thank you.
#define bit_get(p,m) ((p) & (m))
#define bit_set(p,m) ((p) |= (m))
#define bit_clear(p,m) ((p) &= ~(m))
#define bit_flip(p,m) ((p) ^= (m))
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
#define BIT(x) (0x01 << (x))
#define LONGBIT(x) ((unsigned long)0x00000001 << (x))
Are there any good places to learn more about the underlying code that gets generated when you make a program with Windows Form (C# version)? I recently made an event based calculator but I also need to explain how all the classes fit together and cooperateAnd I have no clue what all these things do xD
Thanks, I think the newboston and F12 will suffice. Hopefully, reading up on the eventHandler and such is enough.Hopefully I am understanding what you are asking.
For general information on C# as a language, the new boston (http://thenewboston.org/list.php?cat=15) is decent for understanding C# a bit better.
If you are specifically asking about a certain portion of code, click on the portion of code and hit F12. F12 allows you to go to the definition of a portion of code. This allows you to see the underlying details of what you program.
If you want to go deeper you can use ildasm.exe to view the MSIL code. Here's a tutorial:
http://msdn.microsoft.com/en-us/library/aa309387(v=vs.71).aspx. It's using the old Framework 1.1, but I'm assuming it will still work fine if you need to go that deep.
Good luck!
Are there any good places to learn more about the underlying code that gets generated when you make a program with Windows Form (C# version)? I recently made an event based calculator but I also need to explain how all the classes fit together and cooperateAnd I have no clue what all these things do xD
D.Rosen from Wolfire (Lugaru, Overgrowth) has written an interesting blog post covering this topic (link), worth reading.
Similar to what Kalnos says, I think the best idea would be to use an interface (this looks like Java), collect the methods that the different types share and put them there, then have the classes you want to put in the arraylist implement that interface.
I am still not far into java so we haven't been introduced to interfaces yet.
Kind of lost on what to do for this assignment. Any guidance would be great. Thank you.
What exactly is your assignment? Just parsing the textfile? You could write a class for each shape with attributes such as isFilled, fillColor, width, height etc. and create an object for each line of text. Then set the attributes of that object accordingly. If you write some getters and setters you can easily alter or retreive the value of each attribute.
I would take it with a grain of salt though, since the author seems somewhat opposed to proprietary software and Microsoft in general. Saying that OpenGL is more powerful than DX an then putting some Utah Teapot Wireframe rendering right below that is a bit naive. Also the claim that 50% of gamers still use XP is invalid now (since the article is 3 years old).
Thanks for the quick response. Yes my assignment is checking a text file that has the type of shape (rectangle or circle and it's attributes). I already created classes for each one and it's getters and setters but having a hard time how to place these attributes into an arraylist and then adding the total area.
//Create lists
ArrayList<Rectangle> Rectangles= new ArrayList<Rectangle>();
ArrayList<Circle> Circles= new ArrayList<Circle>();
//Add new object to list
Rectangles.Add(new Rectangle(color, isFilled, width, height));
//Iterate over list
int rectangleArea = 0;
for (Rectangle rec : Rectangles){
rectangleArea += rec.getArea();
}
//Add up everything
int fullArea = rectangleArea + circleArea;
System.out.println("Overall area is "+ fullArea);
Got an interview for a backend jr java dev position at AT&T tomorrow.
What kind of technical questions can I expect?
You don't need to place the attributes into an Arraylist, but the objects. If you don't have a superclass "Shape" or similar, create an Arraylist for each type of shape, iterate over the list and add up the area. Than add up the area of all lists.
Something like this:
Code://Create lists ArrayList<Rectangle> Rectangles= new ArrayList<Rectangle>(); ArrayList<Circle> Circles= new ArrayList<Circle>(); //Add new object to list Rectangles.Add(new Rectangle(color, isFilled, width, height)); //Iterate over list int rectangleArea = 0; for (Rectangle rec : Rectangles){ rectangleArea += rec.getArea(); } //Add up everything int fullArea = rectangleArea + circleArea; System.out.println("Overall area is "+ fullArea);
I do have a superclass called GeometricObjects. I appreciate your input.
//Create list
ArrayList<GeometricObjects> MyObjects= new ArrayList<GeometricObjects>();
//Add new object to list
MyObjects.Add(new Rectangle(color, isFilled, width, height));
MyObjects.Add(new Circle(color, isFilled, radius));
//Iterate over list
int area= 0;
for (GeometricObjects obj: MyObjects){
area += obj.getArea();
}
If you haven't figured it out already, start by looking in Program.cs. That'll be the main entry point when your program is run. It probably just makes a new Form1 and then shows it or something. Then you can look at the code for Form1 (either hit F12 when your cursor is on it or find it in solution explorer). Look at the constructor first, then any other code that gets called. From there you should be able to find all the code.Thanks, I think the newboston and F12 will suffice. Hopefully, reading up on the eventHandler and such is enough.
I remember your question before, but I was never very clear what you're trying to do and what you're having problems with? Is there any way you can provide more details on what part is stumping you?Thanks for the quick response. Yes my assignment is checking a text file that has the type of shape (rectangle or circle and it's attributes). I already created classes for each one and it's getters and setters but having a hard time how to place these attributes into an arraylist and then adding the total area.
I remember your question before, but I was never very clear what you're trying to do and what you're having problems with? Is there any way you can provide more details on what part is stumping you?
If I recall you have a text file to parse, where each line defines a shape and you have to calculate the area of the shape defined by the line of text. What does an arraylist have to do with where you're stuck?
This problem is based on the GeometricObject class introduced in chapter 13.
Write a Java program to create an ArrayList holding Circle and Rectangle objects. The program will
traverse the list adding the area of all objects in the collection. At the end, the program prints the grand
total. Test your program with the sample disk data shown below.
Hints:
1. Define an ArrayList<GeometricObject> object, call it list.
2. Define the abstract class GeometricObject and its subclasses Circle and Rectangle as
indicated in chapter 13 (already discussed in class).
3. For each row in the input file
a. Create a new Circle or Rectangle object.
b. Add the new object to the list.
4. Traverse the list adding each objects area to an accumulator
5. Print the total area
Observation
Each line begins consists of several strings. The first string indicates the objects type (Circle or
Rectangle). In the case of a circle the next token represents either its radius (in case it is numeric) or the
objects color, followed by its filled attribute and finally its radius. Similar strategy is used for Rectangle
objects.
It's for a course so I probably need to explain it all no matter how trivialThe designer only generates the code in the *.Designer.cs file, which is mainly a bunch of attributes for all your controls, as well as the initialization of the event handlers. There isn't really that much to explain about, there is a reason that it gets put in a partial class (you usually doesn't need to touch it, since it can get overwritten any time).
Thanks, sounds like a smart move. I probably need to read up on the background theory in the course litterature too though.If you haven't figured it out already, start by looking in Program.cs. That'll be the main entry point when your program is run. It probably just makes a new Form1 and then shows it or something. Then you can look at the code for Form1 (either hit F12 when your cursor is on it or find it in solution explorer). Look at the constructor first, then any other code that gets called. From there you should be able to find all the code.
Sorry about you feeling overwhelmed. It is very common, which sucks.I am just confused on a lot of subject when it comes to coding. Kinda feeling over-whelmed to be quite honest. I will just post the homework assignment so you may get a clear understanding of what I am trying to do here:
Circle 1
Circle red true 1
Rectangle 10 20
Rectangle blue true 1 5
Scanner s = new Scanner(new File("mydata.txt"));
ArrayList<String> shapeLines = new ArrayList<String>();
while (s.hasNextLine()){
shapeLines.add(s.nextLine());
}
s.close();
for(String shapeLine : shapeLines) { //we want to do this for all the lines of text we read from the file
String[] shapeWords = shapeLine.trim().split(" "); //we split the line by spaces, so now this has each individual word from the line shapeLine.
//we'll use the words here, since they only exist for this iteration of the loop
}
for(String shapeLine : shapeLines) {
String[] shapeWords = shapeLine.split(" ");
if(shapeWords.length > 0) { //just in case one of the lines from the file was blank, we only want to convert it into a shape if there are actually any words in the array
String shapeType = shapeWords[0]; //the first word, which should be Rectangle or Circle
if(shapeType == "Rectangle") {
//make a rectangle here, using the other words
}
else if(shapeType == "Circle") {
//make a circle here, using the other words
}
}
}
for(String shapeLine : shapeLines) {
String[] shapeWords = shapeLine.split(" ");
if(shapeWords.length > 0) {
String shapeType = shapeWords[0];
if(shapeType == "Rectangle") {
if(shapeWords.length == 3) { //"Rectangle" "10" "20" is 3 words, so this is the case where there is no color or filled
int width = Integer.parseInt(shapeWords[1]);
int height = Integer.parseInt(shapeWords[2]);
//make the rectangle here
}
else if(shapeWords.length == 5) { //"Rectangle" "blue" "true" "1" "5" is 5 words, so this is the case where there is everything
String color = shapeWords[1];
boolean filled = Boolean.parseBoolean(shapeWords[2]);
int width = Integer.parseInt(shapeWords[3]);
int height = Integer.parseInt(shapeWords[4]);
//make the rectangle here
}
}
else if(shapeType == "Circle") {
if(shapeWords.length == 2) { //"Circle" "1" is 2 words, so this is the case where there is no color or filled
int radius = Integer.parseInt(shapeWords[1]);
//make the circle here
}
else if(shapeWords.length == 4) { //"Circle" "red" "true" "1" is 4 words
String color = shapeWords[1];
boolean filled = Boolean.parseBoolean(shapeWords[2]);
int radius = Integer.parseInt(shapeWords[3]);
//make the circle here
}
}
}
}
else if (shapeWords.length == 4) {
String secondWord = shapeWords[1].toLowerCase();
boolean filled = false;
String color = "";
if(secondWord == "true" || secondWord == "false") {
filled = Boolean.parseBoolean(secondWord);
}
else {
color = secondWord;
}
//make the rectangle here, dealing with the possibility of color being an empty string.
}
ArrayList<GeometricObject> shapes = new ArrayList<GeometricObject>();
for(String shapeLine : shapeLines) {
String[] shapeWords = shapeLine.split(" ");
if(shapeWords.length > 0) {
String shapeType = shapeWords[0];
if(shapeType == "Rectangle") {
if(shapeWords.length == 3) {
int width = Integer.parseInt(shapeWords[1]);
int height = Integer.parseInt(shapeWords[2]);
Rectangle rect = new Rectangle(width, height);
shapes.add(rect);
}
else if(shapeWords.length == 5) {
String color = shapeWords[1];
boolean filled = Boolean.parseBoolean(shapeWords[2]);
int width = Integer.parseInt(shapeWords[3]);
int height = Integer.parseInt(shapeWords[4]);
Rectangle rect = new Rectangle(color, filled, width, height);
shapes.add(rect);
}
}
else if(shapeType == "Circle") {
if(shapeWords.length == 2) {
int radius = Integer.parseInt(shapeWords[1]);
Circle circle = new Circle(radius);
shapes.add(circle);
}
else if(shapeWords.length == 4) {
String color = shapeWords[1];
boolean filled = Boolean.parseBoolean(shapeWords[2]);
int radius = Integer.parseInt(shapeWords[3]);
Circle circle = new Circle(color, filled, radius);
shapes.add(circle);
}
}
}
}
Circle blue 1
- Make shape objects from a text file
|- Read lines from the file
|- Use Scanner and nextLine
|- Make a shape from each line
|- Break each line down into words
|- Use the words to make a shape
|- Use the first word to determine the shape
|- Convert the rest of the words into properties of the shape
|- Use the number of words to determine which words correspond to which properties of the shape
|- Use integer.parseInt and Boolean.parseBoolean to convert some of the properties
Clear the three bits in n1:
n1 = n1 & 0xFFF8;
(use 0xFFF0 if 4 bits, 0xFF00 if 8 bits)
Prepare n2, clearing all unimportant bits:
n2 = n2 & 0x0007;
(use 0x000F if 4 bits, 0x00FF if 8 bits)
Well, it comes from thinking using bitwise logic, and applying it to get a number useful for whatever you need to do. First, the properties of AND, OR, and XOR:Thanks for everything, specially for those sexy functions.
I have a question about this:
How do you come with a number like"0xFFF0" ? Is there a formula?
Thank you!
I'm having a hard time digging anything up specifically on AT&T interview questions. Did you ask if they are going to have to you code/answer technical questions or if it's a behavioral interview?
If it's just technical questions, then I would brush up with something like this:
http://www.techinterviews.com/master...view-questions
It's a little old, you might be able to find something newer. Most of it is relevant though.
If it's coding then go over your data structures and algorithms.
If it's behavioral, then be yourself and do a mock interview as prep.
Usually I can dig up some stuff on Glassdoor.com as far as interview questions, but couldn't find anything for AT&T.
(MSB) (LSB)
BIT | 7 6 5 4 3 2 1 0
+---------------------------------
VALUE | 128 64 32 16 8 4 2 1
DEC || 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
======++================================================
HEX || F E D C B A 9 8 7 6 5 4 3 2 1 0
8 + 2 is 10. just sayin1010 -> 1*8 + 0*4 + 1*2 + 0*1 = 12
I... I don't know what you're talking about. *cough*8 + 2 is 10. just sayin![]()
Hmm? That's a fine explanation, but I do know my bases pretty well already, thanksColtraineGF, Hex to Bin and back is rather easy once you "get it".
That link is quite useful, bookmarked thanks!
Speaking of interviews, how 'important' is technical questions for entry level positions? I always tend to fumble on those
Not really good at textbook questions.
Hmm? That's a fine explanation, but I do know my bases pretty well already, thanks![]()
Anyone know why when I keep getting zombie (read defunct) process when I fork child processes? I tell the parent to wait while the child runs and exits, but the child is still always listed when I use the 'ps' command.
I'm working on a 'shell' (couple basic commands) and ideally all of the defunct processes shouldn't show up when I execute the command from within my shell.
void zombieProcessCleanup( std::vector<pid_t>& vChildProcs )
{
int status;
for( std::vector<int>::iterator iter = vChildProcs.begin(); iter < vChildProcs.end(); ++iter )
{
int testpid = waitpid( *iter, &status, WNOHANG );
// confirms process status has changed, so remove from vector as process will not be in process table anymore
if( testpid == *iter )
iter = vChildProcs.erase( iter );
}
}
Are you actually waiting or using WNOHANG?
I used multiprocessing to make a proxy for my networking class and it was forking 20 or more processes per web page at times which obviously resulted in zombie central so I had to figure out the whole wait thing. I don't know the structure of your program, but with mine I would be waiting until a request comes in from a browser and just after I forked, I would call my zombie process cleanup. I used the following function to do it. I hope it helps. It's not the best code. For example, I'm not even using status, so technically I could just pass in null, but the project was rushed and that slipped. Also, it does skip an element when an element is removed at the moment. I just saw that. Derp derp.
fgets(arg, 10, stdin);
arg1 = strtok_r(arg, " ", &arg);
arg2 = strtok_r(arg, " ", &arg);
arg3 = strtok_r(arg, " ", &arg);
Was just using wait. Upon further inspection that would lead me to believe that that is my issue. guh. I'll have to look into that. Can't use std::vector since it's gotta be all C tho.
Anyway another simple one: I need to split an argument into multiple tokens, and for the most part I'm successful. Problem is, any proper input must be formatted with an extra space when entering it.
Code:fgets(arg, 10, stdin); arg1 = strtok_r(arg, " ", &arg); arg2 = strtok_r(arg, " ", &arg); arg3 = strtok_r(arg, " ", &arg);
So when I want it to process a command, say ls, I have to explicitly type "ls_" because plain ol "ls" won't work. I'm know it has to do with how I'm delimiting it, since I'm assuming strtok_r includes the delimited character (in my case) as the end part of the string...
char *strtok_r(char *str, const char *delim, char **saveptr);
The strtok_r() function is a reentrant version strtok(). The saveptr argument is a pointer to a char * variable that is used internally by strtok_r() in order to maintain context between successive calls that parse the same string.
On the first call to strtok_r(), str should point to the string to be parsed, and the value of saveptr is ignored. In subsequent calls, str should be NULL, and saveptr should be unchanged since the previous call.
No problem.Thank you so much. I really appreciate your time and effort into helping. I did put some work into my assignment yesterday. Also, my classes for circle and rectangle have a zero argument constructor and a three argument constructor.
How would I implement this into the driver?
I know how to create an object ala Circle c1 = new Circle();, but I have no idea what else to do. Sorry if I ask to many questions. Just sort of lost here.
Thanks again.
Rectangle rect = new Rectangle();
rect.width = width;
rect.height = height;
//and if you have these values (only in some cases):
rect.color = color;
rect.filled = filled;
C++ or Java or both?Hi programming GAF,
I'm currently taking an introductory class in Python to be used in bioinformatics. But I also have a goal to make my first android app by the end of the year. I have no idea what kind of app I want to make but its just a little goal I've set for myself. What other languages should I start learning on the side to prepare for this? I'm working off the assumption that once I finish this semester of python being taught from an instructor picking up other languages from Google won't be as much of a challenge.
Hi programming GAF,
I'm currently taking an introductory class in Python to be used in bioinformatics. But I also have a goal to make my first android app by the end of the year. I have no idea what kind of app I want to make but its just a little goal I've set for myself. What other languages should I start learning on the side to prepare for this? I'm working off the assumption that once I finish this semester of python being taught from an instructor picking up other languages from Google won't be as much of a challenge.
Do you have any more details? Like, do you have to do it in a particular language? Do you have to take the input values from any particular location? What part do you need help with?I need help with a program. I need to Write a function that takes one numeric parameter as students grade and returns letter grade value for that grade. These are the grades i need to do it with:
>93 "A"
90-93 "A-"
87 - 93 "B+"
84 - 87 "B"
80 - 84 "B-"
75 - 80 "C+"
70 - 75 "C"
<70 "F"
Do you have any more details? Like, do you have to do it in a particular language? Do you have to take the input values from any particular location? What part do you need help with?
It is java script i believe since i do it in html with the <script> tag. He didn't write anything else but i believe he means i need to take each numeric grade and [ex. 90-93] and it needs to return the letter grade[A in this case].
So... advice? C? Or do I jump right into Objective C or C++? Or maybe stick with Python? Too many options...
if ( grade < 70 ) {
return 'F';
}
else if ( grade < 76 ) {
return 'C';
}
else if ( grade < 81 ) {
return 'C+';
}
...
I don't actually think that's what he would want to use since he's looking at ranges of values.
A series of if / else if statements will do.
Basically:
Code:if ( grade < 70 ) { return 'F'; } else if ( grade < 76 ) { return 'C'; } else if ( grade < 81 ) { return 'C+'; } ...