C++ Definition and 813 Threads

  1. R

    C/C++ Printing Int i in If Portion of C++ Code

    I need to print the int i right next to the main, but I need to do it while I am in the if portion of the following code: int i = 7; int main() { int i = 5; cout << ::i; if(1) { int i =9; cout << ::i<<endl; } return 0; } Right now it prints 7. I need it to print 5...
  2. E

    Comp Sci Creating an Array of Pointers to Objects in C++ Without Using Virtual Functions

    Homework Statement suppose i have class A. now i have 2 derative classes: A_1, A_2. i would like to create a 4'th class: Array_Class. Array_Class will have 2 pointers array (one for each class - A_1, A_2). i want to be able to get an object pointer from class A_1 or A_2, and place it in...
  3. Saladsamurai

    C/C++ Eclipse and C++ (Mac): Can we get this working here?

    So I installed Eclipse 3.7.0 (Indigo) for my Mac (Snow Leopard OS). I initially installed the "Java Only" version. That works fine. I then decided I wanted to consolidate to one IDE for both Java and C++ if possible. So, here is what I did: 1) Checked to make sure I have gcc, g++, gdb...
  4. I

    Comp Sci How Does This C++ Program Reverse Individual Words in a String?

    Write a program to reverse words of a string individually, for example if you enter: I love C++, it should display I evol ++C They've given the solution in my textbook but I don't quite understand the logic behind it. void main( ) { int l, i, k = 0 ; char str[80], word[80] ...
  5. I

    Comp Sci Difference between cout and cout.write in C++

    What's the purpose of cout.write. Isn't it pretty much the same thing as cout? For eg, the following code would work the same with cout and cout.write int main( ) { char string[80] ; cout<<"Enter string\n" ; cin.getline(string, 80) ; int x1 = strlen(string) ; for(int i = 0...
  6. C

    C/C++ C++ operator++ overloading, prefix vs postfix

    I have seen how people implement the prefix and postfix ++ overloading, which are as follow: Number& operator++ () // prefix ++ { // Do work on this. return *this; } Number operator++ (int) // postfix ++ {...
  7. F

    Comp Sci C++ Binary Search Tree preorder printing tree problem

    Q.When run the program should ask for an input file containing integer keys to be added to the search tree. The file will contain one key per line. Add these keys in the order given in the file to the search tree. Then print the entire tree using preorder traversal i.e., root, left-child...
  8. N

    Comp Sci Towers of Hanoi Problem in C++: Solving the Classic Puzzle with Recursion

    I have to write a C++ program for the problem listed below, but i can't get it working properly, can anyone find the problem: Question: 5.36 (Towers of Hanoi) Every budding computer scientist must grapple with certain classic problems, and the Towers of Hanoi (see Fig. 5.19) is one of the...
  9. T

    C/C++ Beginner programmer looking for c++ book

    Hello I am a senior in high school and I am required to do a senior project with a research paper related. My project adviser says I need some sort of book that has lessons or something that can be shown as work that I did during my project. I have next to no experience with computer programming...
  10. L

    C/C++ What is the difference between C++ and a compiler

    Hello, I would like to start programming in c++ and after doing a quick internet search, I'm not sure where to start. From what I've read, I know I need a compiler, but my confusion arises from the fact that I don't understand what the difference is between the language c++ and its compiler...
  11. G

    C/C++ Need help in putting data into an array in c++

    Hi guys, I need to create an array in c++. But before I declare how many elements are in the array I want to prompt the user for input. I want to ask the user how many elements do they want in the array. What ever the user said, 5 or 20. I then want to enter these 5 values or 20 values...
  12. S

    Engineering  Calculate Equivalent Resistance of Resistors in C++

    Write a program that prompts the user to enter the resistance of each resistor continuously by using a while loop until a zero resistance is entered and store it in an array, then calculates the equivalent resistance R. Also count the number of resistors n. Test your program with R1 = 1 kΩ,R2 =...
  13. D

    Comp Sci Erase line in C++ console program

    Homework Statement How do I erase previous lines displayed from printf function? (use printf, scanf etc) Welcome to Sample Program [Press Enter to Start] When I press Enter, the [Press Enter to Start] should disappear. Homework Equations - nil - The Attempt at a Solution...
  14. G

    C++ or Java for Undergraduate Research Oppurtunities?

    Hello, everyone. I've been learning how to code for a bit. I picked Python because I figured I'd be able to skip the issues I would otherwise have with syntax and focus more on the programming aspect of it. Soon, though, I'm going to be ready to dive into one of the other languages with a...
  15. Z

    C/C++ Converting string to integer using atoi in C++

    Hello, the problem that I was asked to complete was ; Write a program that inputs a string and reverses it. After the string has been reversed you must convert it to an integer and then take the square root of the integer. (using atoi) My code is as follows: int main () { int i=0,L=50...
  16. R

    C/C++ Any ideas for a small c++ code I could make?

    I thing I've got the hang of the basics of c++ and want to try and make some thing that actually has a function other than just making code to calculate something that I could already have done using a calculator. Anyone got any ideas and then when I make I code post my code and see if any...
  17. R

    C/C++ RollCast's Classic Salmon Fly Proportion Calculator | C++ Help

    #include <iostream> using namespace std; int main() {cout<< "Welcome to RollCast's Classic Salmon Fly Proportion Calculator!"<<endl; cout<< "Please enter the gape of your hook in mm."<<endl; int gape; cin>> gape; cout<< "Your hook gape ="; cout<< (gape); cout<< "mm"<<endl; cout<<...
  18. A

    Comp Sci Function 'for' and 'while' in C++

    Homework Statement What is the difference between these two functions? Homework Equations The Attempt at a Solution
  19. P

    Comp Sci C++ Program Help (Newtons method)

    I'm new to programming. my assignment wants me to create a program using c++ that can find the square root of any number using Newtons Method. The user has to enter a number (y) and the program has to calculate the root and has to show each iteration. the initial guess (x0) has to be y/4...
  20. nukeman

    Comp Sci Need help with C++ samples. Basic intro stuff. Thanks

    Homework Statement I am getting ready for a midterm, and I got a list of stuff to study for the exam. Since I was put into the class late, I missed some intro stuff. Can some of you, whom probably know some good resources, give me a link or show me a sample code of the following: ...
  21. nukeman

    Comp Sci My C++ simple program is not compiling - Need help, thanks

    Homework Statement Ok, I just finished my code for my program. And its not compiling, and I am not sure what's wrong. Below is an image of the errors and the code. http://i55.tinypic.com/in8x0y.png And my full code is below here: MOD NOTE: I indented the code below to make it...
  22. U

    Comp Sci Input Validation for only positive integers C++

    Homework Statement I created a program that will calculate the factorial of the number entered and am having a hard time getting it to not accept decimals or fractions.#include <iostream> using namespace std; int main (){ int q=0; int number = 0; cout<<"Please enter a positive whole...
  23. U

    Comp Sci C++ Mode calculator problem (noob having problems)

    Homework Statement Just as a background this is my first time ever learning to program. I am in an engineering C++ class. I had to write a program that took in ten random numbers and then found the mean median and mode. I got the first two and was able to figure out how to sort correctly. But...
  24. J

    C/C++ Are there any good sources for learning Java as an experienced C++ programmer?

    I'm an experienced C++ programmer looking to learn Java SE 7. Because of the similarities of the language, you'd think there would be a tutorial out there suited for such people but I'm having trouble finding one. I've looked at a couple of Java tutorials that are tailored to C++ programmers...
  25. R

    C/C++ How to Create Patterns in C++ with For-Loops?

    How to create patterns using C++? I am new to programming and would really appreciate some help in creating patterns. For example, how will you create this pattern using two for-loops? * ** *** **** ***** And btw, this is not a homework question. Was just curious. Thanks. And please...
  26. W

    Comp Sci Mulitplication Table in C++ with Loops

    I have to write a program in c++ that can be repeated as many times as needed. It should ask for a number to multply like Enter a number to multply: 5 output is this 1 x 5=5 2 x 5=10 3 x 5=15 4 x 5 =20 5 x 5 =25 Enter a number to multiply : 8 1 x 5=5 2 x 5=10 3 x 5=15 4 x...
  27. nukeman

    Comp Sci Need help writing C++ program that counts non-whitespace characters ?

    Need help writing C++ program that counts non-whitespace characters...? Homework Statement Here are instructions... Write a program - stored in the file charcounter.cpp - that will read and count non-whitespace characters from the standard input stream - until some special character is...
  28. nukeman

    Comp Sci Simple c++ program error ? Help, thanks

    Homework Statement Its a simple temp conversion program. NOW, my problem is when ever I enter a temperature to convert, it just keeps repeating NON stop until i hit ctr-C - Here is the code below. What am i missing and how do i fix this little error? / This program ...This program...
  29. J

    C/C++ Decimal number from whatever base the user inputs c++

    Hey all, I am majoring in math and taking this c++ which I am having some trouble with. [Im into paper and pencils ] So my assignment is to have a number saved in a string then convert it from a string to an integer (have that done) and finally convert that number to a decimal number from...
  30. nukeman

    Comp Sci Can someone look over my C++ code - Simple short code

    Homework Statement My computer crashed, so I can't check my code I wrote, and the school linux lab is full, so I really need some help. I already wrote the code (ill post it below) so I can't compile it and check for some errors. Can anyone quickly glance it over and see any mistakes...
  31. E

    Comp Sci C++ and Radial Probability Density

    Homework Statement In a neutral hydrogen atom, the electronic ground state 1s, and excited state 2s, are given by wave functions ψ1s = 1/π1/2 1/a3/2 e-r/a ψ2s = 1/(32π)1/2 (2-r/a)2 e-r/(2a) where "r" is the radial distance to the nucleus, and "a" is the Bohr radius. Write a C++ program...
  32. E

    Comp Sci C++ Factorial Calculator Exercise Solution

    Homework Statement Write a C++ code factorial.cc that calculates the factorial of an integer by direct multiplication. Start with your code in exercise (3), and modify it so that it gets "n" from the user and prints out n! = 1*2*3*...*(n-1)*n. To do this, use a "for" loop: int nfac...
  33. V

    Comp Sci  Print Prime Numbers b/w Two Given Numbers

    Wanted help in c++ ! Program to print the number of prime numbers between two user given numbers. MY ATTEMPT TO SOLUTION : I hv found how to print the prime numbers between two given numbers but couldn't print the number of prime numbers between two given numbers. #include<iostream.h>...
  34. N

    C/C++ Reading a string from file until whitespace c++

    I am newbie to programming , I am trying to write a program in c++ to read strings from the file until white space [ space/ newline] each time i encounter white space i append to the string read append a symbol "$" and push to the buffer. and for the same string append another symbol "(" and...
  35. S

    C/C++ Which IDE is Best for Learning C++ on Windows 7?

    So I've been exposed to C a little with Arduinos and I've been wanting to learn some C++ for a while. Just wondering if anyone has any suggestions on what software I should start with. Right now I kinda need my computer for school so I'd prefer to keep it neat and not install a bunch of tiny...
  36. R

    C/C++ Is C++ code different on mac and PC

    I'm about to start a module in C++ programming and I was just wondering if the code I learn in college (on P.C's) will be useable on macs Xcode. As in will I be able to EXACTLY the same code on both?
  37. V

    Comp Sci C++ question awesome question challenging too

    C++ question...awesome question...challenging too ! How to write the c++ code for this sort of question...i couldn't get the logic even... to print the factors of a number given by the user in a pyramid pattern...like if 4 is the number given by the user...its factors are 1,2,4...the we hv...
  38. B

    C/C++ Image processing in visual studio c++

    how can i work with images in visual studio c++? i want to work with .jpg images. So how do i store them and access them?
  39. U

    C/C++ Why Use Public in C++ Class Inheritance?

    I just came across another question while brushing up on my c++. If you have a base class that uses virtual methods, when you try to use it to define a derived class then you *need* to prefix the base class name with "public", as in the following example. class ExampleBaseClass { ...
  40. C

    Comp Sci Need help with standard deviation C++ program

    Homework Statement Write a C++ program that accepts 10 floating-point values from a user and determines and displays the average and the standard deviation. All values more than four standard deviations away from the average should be dropped and then the new average and standard deviation...
  41. K

    C/C++ [Ask] How to write laplace transform in c or c++ ?

    [Ask] How to write laplace transform in c or c++ ?? Hi Guys.. if I have a laplace transform example : T(s) = 1/s+1. It's easy to solve or write in Matlab, but how to write it in C programm ?? thanks :)
  42. S

    C++ Compiler For Mobile Devices

    Many of us might have used compilers on our personal computers.But does anyone know of C++ compilers for handheld devices.They would help us compile programs on the go.
  43. L

    Comp Sci How can I display both miles and kilometers in a table using a C++ function?

    [b]1. write and test a c++ function named MakeMilesKmTable() to display a table of miles converted to kilometers. the argument to the function should be the starting and stopping values of miles and the increment. the output should be a table of miles and their equivalent kilometer values. use...
  44. pairofstrings

    C/C++ What is the purpose of data structures in C and C++?

    What is data structures in C and C++ all about? I heard that data structures are useful in constructing menu items of any software's menu bar. Is it true? Please tell me more examples of the applications of data structures in real life. Thanks.
  45. S

    C/C++ Optimal Container for Storing Vectors in C++?

    What is the best container to store vectors in for C++? Is it possible to declare a vector whose elements are vectors? Or is there some other sort of container that can be used? I was thinking of using a vector of vectors because I need to be able to access specific elements while also being...
  46. S

    C/C++ C++ Help: Sorting with Arrays & Merging Strings

    I'm working on programming my own sorting code in C++ using the divide and conquer algorithm. I'm a novice programmer and I've gotten a little stuck. Let's say you begin your code with an array of distances, dis[4] = {dis1, dis2, dis3, dis4} Then I want to separate this array into...
  47. G

    C/C++ C++ Chemistry Library: Find the Solution

    Hi, Does anybody know about some C++ class which can calculate chemistry formulas? I mean if i have two variables A and B which are some substances then the variable C = A + B, C will be the result of the two substances. I need a class like this for a personal project and i didn't found...
  48. B

    C/C++ C++ Pointers: Solving "g is not defined" & "return" Meaning

    Hello, I'm teaching myself C++. I'm pretty much at level one. Anyway I was trying to make a code, playing with pointers: #include <iostream> using namespace std; int main() { int x; int g; int *p; x = 1 + g; cin>> g; p = &x; cin.ignore(); cout<< *p <<"\n"; cin.get()...
  49. N

    C/C++ Python or C++ for ChemE Major: Which is Most Useful?

    I'm a chemE major, entering my sophomore year. I have used python in physics classes, but that was minimal experience. I want to begin learning a language this summer; I have no other prior experience. My main interest is cryptography, but I don't think this will amount to anything other...
  50. A

    C/C++ Solve ODEs Backwards in Time with C++ Euler Method

    Hi Everybody I am beginner in c++ and I need your help please. I implemented euler method for solving simple ODEs (y' = x -y, y(0)=1)and it is forward in time(from t=0 to t=1) and it worked well, my question is : I want to run this code backward in time(t=1 to t=0) what i have to change in my...
Back
Top