• Support PF! Buy your school textbooks, materials and every day products Here!

Computer Engineering major changed to Physics.

Main Question or Discussion Point

I was a Computer Engineering major, hated it, and changed to Physics. Now it seems like every Physics professor I speak to wants to know if I know C++. I don't, but I know Java very well. I guess if computing is so crucial for a Physicist to know I should continue learning it, although I won't like it.

Anyway, to the point. Anybody know where I can find any good C/C++ tutorials online?
 

Answers and Replies

verty
Homework Helper
2,157
198
Since you know Java very well, I would skip the tuts and jump ahead to the language specification/references.

Well, that's usually how I like to be introduced to new languages.
 
Last edited:
1,629
1
I agree with verty, If you know Java, all you have to learn is syntax, you should already have a grasp of classes and objects, so you could basically just google for C++ tutorials there are about a bajillion.

ALso if you were a Comp Engineering major don't you have any of the programming books or did they teach you java instead of C++?
 
verty
Homework Helper
2,157
198
Also you'll probably want to get a book on algorithms. (I have no opinion about which book since I don't know them well myself)
 
1,629
1
I would rather learn Java than C++, our whole Computer Science and Engineering major changed because IBM asked Penn State why they arn't teaching us java, we want java programmers!

So now they offer java, yay!

PS: Make sure you learn standard java, not the old stuff!
 
Is C++ the most important language for a physicist to learn? How about C, Fortran, or some other one. I know Matlab is important.
 
Pyrrhus
Homework Helper
2,160
1
Well at my school the languages for engineers were Fortran and BASIC. Seems pretty outdated to me, anyway i am self taugh in Object Pascal, which is a language i like.
 
jtbell
Mentor
15,400
3,187
If you already know some programming (e.g. in Java) and don't mind spending money for a dead-tree product, I highly recommend "Accelerated C++" by Koenig and Moo, published by Addison Wesley. It presents a modern view of C++, taking full advantage of the standard library (why re-invent the wheel?).
 
1,629
1
Well at my school the languages for engineers were Fortran and BASIC.
I hope that doesn't include Computer Engineers!
 
Pyrrhus
Homework Helper
2,160
1
113
0
go buy Stroustups the c++ programming language.
 
783
1
Why only one language (esp. for CE and CS majors)?? Here you wouldn't make it out of first year without knowing at least basic MIPS/assembly and have a good working knowledge of C++/Java.

I'm in science and by the end of the year (freshman) I'll have formally learned scheme/java/c++.

I guess it depends on how much you know before you enter uni.

Is C++ the most important language for a physicist to learn? How about C, Fortran, or some other one. I know Matlab is important.
You should know all. Well, I know I wouldn't be programming in fortran but at least being able to read it is important. You can call fortran routines from C/C++ as well. And good luck learning C++ without picking up the majority of C along with it :) (C++ is just a superset of C)

To answer the OP, like others have said you should have no problem picking up C++ as Java stole a lot of syntax from C/C++ (though they might not admit it ;]). Find a condensed book with little intro material and/or look at some OSS or specification/syntax pages.

I've used this place as a reference but haven't looked at it in any detail:
http://www.cplusplus.com/
 
1,629
1
Why only one language (esp. for CE and CS majors)??
He isn't a CS or CE major....

in 2 semesters how do they teach you 3 languages?
Or did you take AP CS courses in highschool to cover your intro to programming and intermediate programming?
 
1,349
2
depending on the size of the application, physicists usually ask for one of f/c/c++ because most simulations these days deal with high performance computing (geometric or numerical) which may be limited in matlab/java. C/C++ usually becuase at some point you want to render or visualize your data.


And its a lot nicer than fortran =] but thats my opinion cuz i started with turbo pascal and turbo C.
printf, fprintf are your friends, i never got the handle on overloading the << and >> operators though i do like overloading math ops.
 
372
0
I use FORTRAN, and have been dabbling in a little Visual C#. FORTRAN is extremely clunky, but it only does what you want it to, no more and no less, which is ideal for teaching programming for beginners.
 
1,629
1
Overloading the >> and << operators are fantastic for reading into and out of a file, you can then populate any type of STL data structure that C++ supplies and do whatever you want with them.

I'm sure C can do it too but the code is so ugly!

C++ can be ugly too if you don't know what your doing but it can also be poetic looking and I have yet to see any pretty C code but I guess that doesn't matter if your a physics major.
 
783
1
Or did you take AP CS courses in highschool to cover your intro to programming and intermediate programming?
At my school you can enter the CS course stream at different points depending on your experience (you have to prove it in some way.) I chose to take a functional programming course even though it was an intro programming course (the 'norm' is a intro course in java) because I hadn't done any functional programming. However, since this is a CS department course they switch over to java close to the end of the second semester to match everyone else (up to basic algorithm design and data abstraction). We learned everything, including mutation and OOP in scheme and then they basically showed us java's syntax and static typing. These two courses were my two electives for first year.

Since I'm really a physics major, one of my core courses first year is a scientific programming class that teaches numerical methods in C++.

It is easier for me as programming was a hobby and I was nearly a CS major. (I did take CS in HS but visual basic sucks :D)
 
783
1
I'm sure C can do it too but the code is so ugly!
LIES!

Code:
#define F 0xF
#define U 512

#define std(x,y)                                     (*x)(const char *,...)=y##f
#define str(l,e,x)                                                       l e,l x
#define mx(p,v1,v2)                                p[3]=v2,p[1]=v1,p[2]=v2,*p=v1
#define vi(n)                                                        q+2,n,q+3,n
#define rt                                                                return

                                                             #include <stdlib.h>
                                                              #include <stdio.h>

                          typedef double n; n *d,*b,*f; typedef unsigned char c;
char _[ ]="    <?%s version=\"1.0\"?>\n<%s %s=\"%d\" %s=\"%d\">\n", q [7][7] = {
"ivory","black","width","height","text"};int v,std(i,scan),std(o,print);

int cc(str(const void*,x,y))
{
        rt(*(n*)x>*(n*)y)-(*(n*)x<*(n*)y);
                                                                               }
        n t(n f,n g,str(n*,x,y))
                                                                               {
        f=*x++-f,g=g-*x,*y=f*f;rt *y+g*g;
                                                                               }
        c*ln(n*p)
                                                                               {
        c*f=((c*)(d+2*(2+v))+2*(p-d)); while(!*f) mx(f,rand(),rand());rt f;
                                                                               }
        n*put(str(n*,f,l),n z)
                                                                               {
        int r=(l-f)/4,p=*(f+(r*=2))<z;rt r>0?put(f+p*r,p?l:f+r,z):f;
                                                                               }
        n*g(n u,n w)
                                                                               {
        n y=u/(U-1),*s=put(d,d+v+2,y),z=w/(U-1),k,l=t(y,z,s,&k),
        m=l,*r[4],g[4],*f; c p; for(mx(r,s,0),mx(g,k,l);
        p=*(1+g)<*g,(m>*(g+1))+(*g<m);s=*f<m?m=*f,*(r+p):s)*(f=g+p+2)=t
        
        (y,z,*(r+p)+=p?-2:2,p+g);rt s;
                                                                               }
        c*a(str(n*,x,r))
                                                                               {
        n*y; int i=0,j=0,k=0,u;for(u=0;y=g(*x+u/4/4.,*r+u%4/4.),16>u;++u)
        i+=*ln(y),j+=*(1+ln(y)),k+=*(ln(y)+2);
        *_=i/u,*(1+_)=j/u,*(_+2)=k/u;rt(c*)_;
}

void tr(n x,n y,n i)
{
        c*h,w;n*m=g(y,i); for(w=4*(x<2);++w<4&&m==g(w/2*x+y,i+w%2*x););       
        for(w=4*(w>3&&(h=x>1?ln(m):a(&y,&i))&&o("<rect style=\"fill:rgb(%d,%d,%d\
        );\" x=\"%f\" y=\"%f\" %s=\"%f\" %s=\"%f\"/>\n",*h,*(1+h),*(2+h),str(F+,
        y,i),vi(x))),x/=2;x>0&&w<4;++w)tr(x,y+w/2*x,w%2*x+i);
}

int main()
{
        long k,r=1e6,h;d=calloc(r,k=sizeof(n)),f=d+r,b=d;

        while(0<(h=i("%lf",b)))*--f=*b++;v=b-d;if

        (!h+v%2+!v&&(r=0x630C65u)){o("\n0x7");while(r-->0)o("F");rt -1;}
        mx((d+v),-r,r);qsort(d,2+(v/=2),2*k,cc);
        tr(U,0&o(4+_,"xml","svg",vi(2*F+U)),0);

        for(b=d-1+r,k=0;r=1,v>k++;b-=2)
        str(o("<%s x=\"%f\" y=\"%f\" fill=\"%s\" %s-anchor=\"end\">%d</%s>\n",
        4+q,str(F+r/2.-5+U**,b,(b-1)),q+r,q+4,k+!o
        ("<circle style=\"fill:%s;\" cx=\"%f\" cy=\"%f\" r=\"3\"/>\n",
        r+q,str(F+r/4.+U**,b,(b-1))),4+q),&&r--,);

        free(d);rt o("</svg>\n")-7;
}
:P
(C obfuscation contest)
 
Last edited:
I was a Computer Engineering major, hated it, and changed to Physics. Now it seems like every Physics professor I speak to wants to know if I know C++. I don't, but I know Java very well. I guess if computing is so crucial for a Physicist to know I should continue learning it, although I won't like it.

Anyway, to the point. Anybody know where I can find any good C/C++ tutorials online?
For C programming, you can't go wrong with K&R The C Programming Language. It's a book, but it's seriously worth it.
 
783
1
For C programming, you can't go wrong with K&R The C Programming Language. It's a book, but it's seriously worth it.
I agree with this! I thought I knew C until I bought this book... you should still definitely pick up something for C++ though.
 
1,629
1
LOLACAUST!
thanks cscott thanks for that delicious mess of code :P
 

Related Threads for: Computer Engineering major changed to Physics.

Replies
1
Views
3K
Replies
3
Views
5K
Replies
5
Views
3K
Replies
0
Views
2K
  • Last Post
Replies
4
Views
2K
Top