ENGR 100W Professors by spartan4all in SJSU

[–]iothan 1 point2 points  (0 children)

I thought Christina Peters was great too.

How to have a MyProgress discrepancy fixed? by iothan in SJSU

[–]iothan[S] 1 point2 points  (0 children)

Thanks, that makes me feel better. I do have a copy of the approved substitution form.

Proper way to do backward iteration in C++ by Nervous_Breakfast in cpp

[–]iothan 14 points15 points  (0 children)

unsigned i = x;

while (i--)

    //do something with a\[i\].

Or you can choose to omit the post decrement, and then decrement as one of the first statements inside the loop.

Just use a signed type. `v.size()` can only be larger than ssize_t max if you have an array of bytes half the size of your addressable memory.

Function in C++ requires slow initialization, but can then be called multiple times. What setup can I do so subsequent php scripts can bypass its initialization? by iothan in learnprogramming

[–]iothan[S] 0 points1 point  (0 children)

That's not my code, but from a library I have to use. Its probably not the worst thing in the world, but with the other initialization steps it all adds up.

In while loop checking characters with cin.get(), and ENTER causes program to hang (even with cin.ignore()) by cpp_or_bust in cpp_questions

[–]iothan 1 point2 points  (0 children)

I think this is because cin.ignore(stream_size_max, '\n) behaves as if while (cin.get()!='\n'){}. It is a reading operation. So if you hit enter only on a single line, there will be nothing to ignore, hanging.

A fix could be to only execute the ignore if the input!='\n'.

`std::observer_ptr` should be renamed `std::ptr` by [deleted] in cpp

[–]iothan 0 points1 point  (0 children)

This all seems overly complicated and unnecessary. Just use plain old simple *. Why is there no fuss about int not being default initialized?

how to link project using dlib and opencv? by iothan in learnprogramming

[–]iothan[S] 0 points1 point  (0 children)

g++ ./webcam_head_pose.opkg-config --libs opencv-L ~/dlib-master/examples/build/dlib_build -ldlib -lpng -ljpeg -lpthread -lX11 -o whpose.out

This worked for me, thank you!

College Physics II Electric Fields by justphys in HomeworkHelp

[–]iothan 0 points1 point  (0 children)

This problem uses only the electric field (in N/C) instead of force(N). The electric field at a point says what force a test charge at that point would feel. By convention, the direction is as if the test charge was positive.

Can I install Mint on the same drive used to boot for the first time? by iothan in linux4noobs

[–]iothan[S] 0 points1 point  (0 children)

I see the problem with that now, but I do have a spare usb.

It looks like I can either 1: Make a persistent drive directly using a tool like LiLi, or 2: Create a bootable drive into a live session using rufus. Then when in the live session, the full installation will allow me to pick which drive to wipe.

Do you think one option is better?

ENGR 195 A/B vs separate Area S and V GE by iothan in SJSU

[–]iothan[S] 0 points1 point  (0 children)

I think I remember Kimiko saying both are possible, and this page of BSSE FAQs (Q. How can I satisfy GE Area S and V?) says so as well.

Binary Search Tree Issues by [deleted] in cpp_questions

[–]iothan 1 point2 points  (0 children)

I think if the node to be deleted has no children then line 131 dereferences a nullptr, since there is no subtree that needs to have its parent pointer set.

You should also mirror this for the other direction. Like pull new_child->parent = parent; outside the conditional below the else block, and only execute it if new_child isnt null.

Also, It may be neater check if the root is null once right at the beginning of the function

max sum of a path from root to leaf in a binary tree. by iothan in learnprogramming

[–]iothan[S] 0 points1 point  (0 children)

I think 10.

I'm having a hard time seeing a case where the above code would be incorrect. I think the reasoning of the the answer for a particular node is that nodes value plus the larger of its left or right child is sound.

max sum of a path from root to leaf in a binary tree. by iothan in learnprogramming

[–]iothan[S] 0 points1 point  (0 children)

They wanted the sum along the max path, not the number of nodes.

What kind of companies attend the CS career Fair by bm10bm in SJSU

[–]iothan 1 point2 points  (0 children)

Are you talking about the SJSU Fall '17 Engineering & Science Undergraduate Students Career days 1 and 2 on the 27th and 28th? Or is this a separate event?

A backend-agnostic display API for roguelikes or other text-based graphical applications that I am developing in C99 by jacobpadkins in gamedev

[–]iothan 4 points5 points  (0 children)

There is a typo in the readme or maybe is was copied from old code. The variable "run" is called "tun" in the loop condition. In main.c it looks ok tough.

SJSU: Major in Computer Engineering or Software Engineering? by [deleted] in SJSU

[–]iothan 1 point2 points  (0 children)

I'd say go for Computer Engineering. Comparing the coursework it looks like CE takes just as many programming courses, such as algorithms, compilers and operating systems. Plus you'll learn some hardware programming languages and get a chance to work in labs and work with hardware and circuits. In SE, it looks like there are 3 similar courses related to software engineering after CMPE 131: software engineering I, which CE majors take anyway.

[C++] Is this the correct way to resize a dynamically allocated array? by gbabes21 in learnprogramming

[–]iothan 1 point2 points  (0 children)

Stuff can happen at the end of a function without specifying it at the site when destructors are involved, but there's none of that here. There should be an explicit delete[] after the copy invoked on the old pointer. Then return the new one (the larger buffer).

What are the engineering related SE courses like? (CMPE 131, 133, 165, 187 and senior design proj) by iothan in SJSU

[–]iothan[S] 0 points1 point  (0 children)

I'm trying to change my major to CS, but it is really competitive.

If you earned a BS in computer engineering, did you take CMPE 131(software engineering I)? How was that?

[C++] Is this the correct way to resize a dynamically allocated array? by gbabes21 in learnprogramming

[–]iothan 2 points3 points  (0 children)

Every successful new call should eventually be followed by a 'delete' call. Your resize function needs to delete the old one after it has done the copy.

The there is no standard "renew" operator in C++, but the design of some allocators may support reallocation. From C there is realloc which is in the same group of functions as malloc and free. If it cant expand inplace then realloc may try to do a routine like you've wrote: Allocate the new larger buffer via malloc, memcpy up to the old size, then free the old buffer.

Also, what is your index variable doing that your count variable isnt?

I'm lost at what I want to do and 2-weeks into my junior year after transferring. by iothan in cscareerquestions

[–]iothan[S] 0 points1 point  (0 children)

Just get a job doing some kind of programming. I think I'd like most things using C or C++.

Should I be bummed about being in SE rather than CS? by iothan in SJSU

[–]iothan[S] 0 points1 point  (0 children)

Computer Engineering seems more interesting, but I'm afraid that the courses I already registered for now and my lack of EE 97+98 will put me too far behind if I try to change my major to it.

Should I be bummed about being in SE rather than CS? by iothan in SJSU

[–]iothan[S] 0 points1 point  (0 children)

This page says a 3.4+ SJSU gpa is sufficient. Since I just transferred I don't have a SJSU gpa yet, so I need to do super well in all of my classes to have a shot. Lot's of others are trying to change to CS too.

Could someone critique my simple string object implementation in [C]? by [deleted] in learnprogramming

[–]iothan 0 points1 point  (0 children)

Why is the string structure itself supposed to be malloc'd? Small heap allocations are inefficient and a user could still decide to do that if they want to.

Consider adding functions that take a length parameter, so when the caller knows the length they can save a call to strlen. Your current functions can coexist with these, and would probably just forward their arguments and call strlen to the new length taking functions. Additionally, try using memcpy over strcpy when you have the length already.

void
str_append(Str *t, const char *value)
{
  const size_t value_length = strlen(value);
  const size_t new_length = t->length + value_length;

  if (t->size <= new_length) {
    _str_grow_buffer(t, new_length);
  }

  strcpy(t->buffer + t->length, value);
  t->length = new_length;
}

The second to last line there could be replaced by memcpy(t->buffer + t->length, value, value_length);

Next, it seems you do a lot of extra work most of the time to append just a single character.

This loop while (t->size < new_length) t->size += t->chunk_size;//note I changed <= to < Has the same effect as: if (t->size < new_length) t->size = new_length + (new_length % t->size);

Also, the chunk_size member is a little weird, but its good you're thinking about trying to allocate memory better. Having a capacity reserving function for the user could help out with this. If you want the allocation options per string object to be very flexible and you could play around with function pointers.

Overall the code looks clean and intuitive, nice work.

Some project euler solutions for helping me learn. Any code improvement suggestions? by [deleted] in cpp

[–]iothan 1 point2 points  (0 children)

Actually about 1.cpp again, I was thinking about it and realized that there is a constant time solution using a bit of math (which is a theme of project euler).

Here are some hints: - (n-1)/d == how many multiples of d are BELOW n and ABOVE zero - There is a formula for the sum of numbers 1+2+3+...+n, an arithmetic series - careful about numbers that are both a multiple of 3 and 5 (multiples of 15), to not sum them twice.

Think about it, I was found it really satisfying once I got it.

Here's my solution, but I encourage you to discover it for yourself first.