I somehow managed to pass the 1st semester but things are getting tough now. The difficulty level of assignments and quizzes is increasing. My friends laugh at me when I am unable to code a C++ program. They complete the task in 2 hours and I take 6 hours for that. This really depresses me. Should I transfer to another major?
a lot of students already knew how to code going in. keep that in mind. When I went to college I had already coded pretty much everything in a standard data structures book -- I knew pointers and such well, and had done the usual text stuff. The first class had a progressive (build a little more each week towards a final product) for a hangman game... several of us were totally done with it by the second week and spent the rest of the semester adding extras like sounds and animations, or helping the new folks with it. And that was long ago... today even more % of people have seen/done code before.
Someone should be able to help you. Some people are not well suited to the major, and you could be one of them, but one semester never having seen it before is a bit early to call it quits IF you think you will like it once you get better at it.
Consider your options. Take a semester 'off' to do your unimportant classes (nonmajor required fluff junk, and your math or tangentially important classes, etc). Use some downtime to practice, redo old problems faster, try new problems, work it. See what happens... give it a chance. Maybe, audit the next class (take it but no grade, just sit in the lectures and practice the homework)
your true friends won't laugh at you. They will help you. See if you can find one.
I was in your same shoes. I was struggling learning to code learning in c++. After 2 quarters i didnt know if i would be able to persue this degree. So i stopped and took a python course at a local community college which helped me learn. I began to get As in all my programming class and got better than most of my classmates. just like what heretohelpyou said. Only thing is yu must put the effort.
My friends laugh at me when I am unable to code a C++ program. They complete the task in 2 hours and I take 6 hours for that.
Get some new friends. I do not know any friends who would do that. How childish and extremely arrogant someone must be to belittle others. Surround yourself with better people who can give better vibes. You're in university - there are plenty of better people to get to know. Try to avoid comparing yourself to others. Impostor syndrome isn't some particularly fun to deal with university, considering you already have other courses burdening you.
My advice would be a combination of @heretohelp you and @jonnin. Keep going. You will certainly learn with time, and it's not at a linear level. Once you understand foundational things in C++, it's so not so difficult to pick up other things. You will start picking things up at an exponential level. If you can't manage, then take some time off. Whatever you do, just don't be one of those students who steals code from Stackoverflow or from here. You wont be learning anything and will be doomed when you get to a data structures course or any course beyond your foundational programming courses.
But, I can tell you that if you do quit now, then CS major isn't for you.
Because your friends took 2 hours and you took 6 hours on a beginner-level assignment, you and your "friends" think that's a huge skill gap? I can present a real world program so complex that you and your friends are going to be lost instantly. At least to me, you and your friends don't have a gap - all of you are equally inexperienced.
What's the point of comparing sizes of acorns. It doesn't matter if one acorn is a little bit bigger than the rest. They are still acorns - all pretty much small and insignificant.
Often, what determines your success in the CS field isn't intelligence or how good you are at coding initially. It's tenacity and passion. If you learn programming for the love of programming and you hang on to it no matter what obstacles or errors you face, you will get there and then you will see the real gap between you and your friends.
One more thing that you should consider is the power of the wonderful Internet. There's all kinds of sources and videos online. And if you get stuck at something then you can go to places like here to clarify even your stupidest doubts. And thankfully people here aren't like those jerks you called as friends.