C++ Definition and 813 Threads

  1. I

    C/C++ Solve C++ "Simon Says" Memory Game with a for Loop

    "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break...
  2. V

    Solving 3D Vectors Physics Programming Question

    Homework Statement A man is standing in his home , his position his facing direction and the position of the sweet dish are given ,if he faces the sweet dish , he eats it . Translating it into CS programming question : write a function -> bool IsManInFrontofDish( vector3& manPosition, vector3&...
  3. I

    C/C++ What Is the Purpose of a Loop Variable in C++?

    what is the purpose of a loop variable (i)? how is it useful?
  4. I

    C/C++ Understanding Cin and Cout Order in C++

    why does cin come AFTER cout and not before?
  5. I

    C/C++ C++ Infinite Loops: Why Do They Occur?

    why do infinite loops occur? is it just because the condition is always true?
  6. I

    C/C++ Detecting First Letter Match in C++ String with Substr Function

    Write an expression to detect that the first character of userInput matches firstLetter. Sample program: #include <iostream> #include <string> using namespace std; int main() { string userInput; char firstLetter = '-'; userInput = "banana"; firstLetter = 'b'; if (<STUDENT...
  7. I

    C/C++ C++ String Access Ops: Assign Size of UserInput

    Assign the size of userInput to stringSize. Ex: if userInput = "Hello", output is: Size of userInput: 5Sample program: #include <iostream> #include <string> using namespace std; int main() { string userInput; int stringSize = 0; userInput = "Hello"; <STUDENT CODE> cout <<...
  8. M

    C/C++ C++ - dynamically allocating memory to array of structs

    Let me start by saying I know this is a funky way to program, but my teacher is requiring us to go about it this way. also: I CANT use std::string, classes, constructors for this project. I am required to use this archaic method of c-style strings with dynamic memory allocation occurring...
  9. I

    C/C++ Two question on string access ops c++

    Assign the size of userInput to stringSize. Ex: if userInput = "Hello", output is: Size of userInput: 5 Sample program: #include <iostream> #include <string> using namespace std; int main() { string userInput; int stringSize = 0; userInput = "Hello"; <STUDENT CODE> cout <<...
  10. I

    C/C++ C++ String Compare: Alphabetize Strings

    Print the two strings in alphabetical order. Assume the strings are lowercase. End with newline. Sample output: capes rabbits Sample program: #include <iostream> #include <string> using namespace std; int main() { string firstString; string secondString; firstString = "rabbits"...
  11. I

    C/C++ What are the Purposes of Strings and Switch Statements in C++ Programming?

    what are the purposes of strings. also what is the purpose of switch statements. would it not be enough to use if else statements instead of switch stmts?
  12. I

    C/C++ How to Write an If-Else Statement in C++ for Balloon Objects?

    Write an if-else statement to describe an object. Print "Balloon" if isBalloon is true and isRed is false. Print "Red balloon" if isBalloon and isRed are both true. Print "Not a balloon" otherwise. End with newline. Sample program: #include <iostream> using namespace std; int main() { bool...
  13. I

    C/C++ C++: What is Boolean Data Type & What Does it Do?

    Boolean refers to a quantity that has only two possible values, true or false. The language has the built-in data type bool for representing Boolean quantities. thats what my book says. i don't really understand the purpose. here's a passage from my book: int main() { bool isLarge = false...
  14. I

    C/C++ How to Use C++ Switch Statements: Examples and Tips for Beginners

    Write a switch statement that checks origLetter. If 'a' or 'A', print "Alpha". If 'b' or 'B', print "Beta". For any other character, print "Unknown". Use fall-through as appropriate. End with newline. Sample program: #include <iostream> using namespace std; int main() { char origLetter =...
  15. I

    C/C++ Solving C++ Logical Ops 2: Print "Special Number

    Write an expression that prints "Special number" if specialNum is -99, 0, or 44. Sample program: #include <iostream> using namespace std; int main() { int specialNum = 0; specialNum = 17; if (<STUDENT CODE>) { cout << "Special number" << endl; } else { cout <<...
  16. I

    C/C++ Compare Smallest and Largest 3-Digit Numbers using Logical Operators

    num is a 3-digit positive integer, such as 100, 989, or 523, but not 55, 1000, or -4. For most direct readability, your expression should compare directly with the smallest and largest 3-digit number. if ( (num >= 100)<STUDENT CODE> ) { ... } so far i came up with ((num >= 100) && (?))...
  17. I

    C/C++ Using C++ Relational Ops to Check if a Number is Even

    Write an expression that will print "Even" if the value of userNum is an even number. #include <iostream> using namespace std; int main() { int userNum = 0; userNum = 6; if (<STUDENT CODE>) { cout << "Even" << endl; } else { cout << "Odd" << endl; }...
  18. A

    C/C++ How can I perform symbolic computation in a C++ program?

    Don't know where else in Phyiscs Forums or on the internet in general to ask this, and if it's inappropriate here, I apologize. My question is: is there an open source library or resource that I can access from a C++ program to perform symbolic computation on the level of something like Maple...
  19. I

    C/C++ How to Calculate a Student's Total Course Percentage in C++?

    The following incomplete program should compute a student's total course percentage based on scores on three items of different weights (%s): 20% Homeworks (out of 80 points) 30% Midterm exam (out of 40 points) 50% Final exam (out of 70 points) Suggested (incremental) steps to finish the...
  20. I

    C/C++ Using Constant Variables in C++ for Shipping Cost Calculation

    i don't even understand this... Given shipWeight in pounds, compute the cost to ship a package and assign to shipCost. Shipping involves a flat fee of 75 cents, plus 25 cents per pound. Declare and use a const named COST_PER_POUND. Sample program: #include <iostream> using namespace std; int...
  21. I

    C/C++ What is the equation for computing the volume of a sphere using C++?

    Given sphereRadius and piVal, compute the volume of a sphere and assign to sphereVolume. Look up the equation online. Use (4.0 / 3.0) to perform floating-point division, instead of (4 / 3) which performs integer division. Sample program: #include <iostream> using namespace std; int main() {...
  22. kartikwat

    C/C++ Object based programming in C++

    What does object based programming mean?how does it localises the implementation details ,i tried to read it from book but i dint got it.
  23. Ascendant78

    C/C++ Why am I getting no output in Code::Blocks for my C++ program?

    I am trying to do an introductory course on C++ through OCW (MIT). However, there is this one they tell you to try that I keep running into a problem with. This is the information they tell us to input: #include <iostream> using namespace std; int main (){ int x; cin >> x...
  24. B

    Comp Sci C++ Error in function call that I don't understand

    Hi there- I'm trying to check an array for ascending order and if not to print out the number that is out of order by using a function. I solved it by not using a function but when I've tried to use a fxn for some reason it tells me that in my call for the fxn the numbers "argument of type int...
  25. J

    C/C++ Getting back into C++ with knoppix

    Been a long time since I did any C/C++. I have an older version of knoppix which looks like it might have C++. I'll need some step by step help here - don't know very much. I go to the menu, go to "Development", and there is a "KDevelop: C/C++ (IDE for C/C++)". Should I click on this or...
  26. J

    C/C++ C++ function to tell whether a group is cyclic

    Is there anything wrong with my logic and is there any way to further optimize this potentially long-running function? I've put a lot of comments to explain what's going on. template <typename ObType, typename BinaryFunction> bool isCyclic(const std::set<ObType> & G, BinaryFunction & op...
  27. fluidistic

    C/C++ Why Does My C++ Code Result in an Infinite Loop?

    I don't understand why I enter in an infinite loop with the following code: #include <iostream> //for cout #include <cstdlib> //for rand() #include <ctime> // for time() #include <fstream> //to write into a text file using namespace std; static const int M = 3; ofstream myfile; int...
  28. D

    Comp Sci Diagonalizing Matrices in C++: A Beginner's Guide

    Homework Statement Hi :) I want to write a program in c++ to diagonalize given matrix. However, I'm stuck and I don't have any ideas to do it. I found a linear algebra library for c++ but I could not solve my problem because I don't know how to solve a 2nd order equation. Can you help me...
  29. J

    C/C++ Help figuring out this C++ compile-time error?

    My compiler doesn't like something about my enumerator declaration. Maybe something else too. I'm trying to figure it out. Code: #include <string> namespace CalcWizConsts { char varChars[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'...
  30. J

    C/C++ A C++ Program for Differentiating a Function: Is this a Good Start?

    Here's what I have so far: std::string CalculusWizard::derivative(std::string& fx, const char & x, unsigned & n = 1) { if (n == 0) { return fx; } else if (n > 1) { while (n-- > 1) fx = derivative(fx, x); } // If here, find and return the derivative of fx ...
  31. V

    Comp Sci Why Does My C++ Linked List Program Freeze After One Use?

    Homework Statement The program is supposed to take in a text file that has a letter and an integer on each line separated by a space. The integer is the order the letter is supposed to come in. The assignment is to write a program that takes the letters and inserts them using pointers into...
  32. Superposed_Cat

    C/C++ C++ DirectX skipped when looking for precompiled header

    Hi all, I main c# and XNA, but XNA is really outdated and requires the player (I'm using XNA for game making) to install it, i wanted to use something windows native so i decided to choose Direct X because i knew some c++. I copied and pasted code to open a blank window to look through but I get...
  33. A

    C/C++ How to Improve the Design of a Linked List Class in C++?

    I decided to make a library for some common data structures and I'm facing some design problems. I wanted to implement linked list using classes in c++. Here is the sample class:- class Linked_List { private: int key; Linked_List* next; public: Linked_List(int key)...
  34. A

    Comp Sci C++ Character Processing Algorithm

    Homework Statement Hey guys! Thanks for taking the time to help me out, I really appreciate it. I am in my second semester of college, taking my first C++ course, and I had never programmed before this class so I am kind of stuck on a problem. I have almost the entire assignment figured out...
  35. S

    C/C++ C++ programming on prime numbers

    this is the program which i wrote: #include<iostream.h> #include<conio.h> #include<stdlib.h> void prime(int p) { if(p==0||p==1) { cout<<"neither prime nor composite"<<endl; getch(); exit(1); } for(int i=2;i<p/2;i++) { if(p%i==0) { cout<<"composite"<<endl; break; } else...
  36. perplexabot

    C/C++ What's Wrong with My Haversine Formula Calculation in C++?

    Hello all. So i am trying to calculate the distance between two points on the Earth's surface. Here is what I have: //calculate distance here dlat = abs(startLoc.lat - tarList[i].lat); dlon = abs(startLoc.lon - tarList[i].lon); a = pow(sin(dlat/2),2) + (...
  37. TheDemx27

    C/C++ C++ Super Simple Download Calculator (if/else stuff)

    Just upgraded my internet, and I want to upgrade my download calculator along with it, since I find many programs give me shaky and inaccurate download times. I rigged my network so I can switch between my slow speed and fast speed DSL. The problem is the "if / else" statement at the end of...
  38. H

    C/C++ App that counts probabilities in c++

    Hey,I am making an app that counts probabilities in c++(win32){for those who knows}. I have found three formulas of equation,but I need some help for one. For example we have a die,and we hit it 6 times. Can we count with an formula,the probabilities to have the number "5",three times...
  39. G

    C/C++ C++ pause and resume while(true) loop

    How to design a class, that executes an infinite loop, but may be paused, resumed and stopped by user input? I'll give you an example class Simulation { public: void start(){ m.init(); while(!m.isFinished()) m.update(); // computationally expensive calculation } void pause(); void...
  40. M

    Comp Sci C++ object oriented, classes/methods

    Homework Statement The problem statement is very long, but in a pinch, I'm supposed to take a text file and use 2 different classes, Song class, and Song_Library class to sort, print, etc.. I'm running into the problem(among others) of my output being really really dumb. And I think it's in...
  41. P

    C/C++ Age Demographics of C++ Developers and Ageism in the Tech Industry

    On average how old are they in your area ? Is there any of 45 and still being a coder ? I'm thinking about applying for a job as one at my current age (38). I m afraid the company hiring mw may have a young man of 24 be my team leader. In theory it is fine but truth is noooo not ok at all
  42. Superposed_Cat

    C/C++ Why do you need FORTRAN, C, C++ for physics

    Okay I get that FORTRAN was made for science and C AND C++ are fast but why do you have to know one of them? (or so I heard). Thanks for any help.
  43. Superposed_Cat

    C/C++ What is causing my C++ program to truncate Euler's number?

    Hi, just started c++ and I made this program to calculate the value of eulers number. It works in c# but truncates the decimal points as far as I can tell. What am I doing wrong? #include <iostream> using namespace std; int factorial(int a){ int b=1; while(a>0){ b=b*a...
  44. I

    C/C++ MSVS C++ compiler:Visitor/iterator patterns and tree parsing

    While creating the compiler, did they use these patterns to process the syntax/grammar trees ? I use MSVS C++ as a specific example, it can be any compiler in general. Thank you a lot.
  45. L

    Comp Sci How to Ensure a C++ Program Reads Exactly 52 Mappings from a File?

    Homework Statement This program must read two input files, one is a key that specifies the conversion of characters the other is a text message that will be encoded based on the mapping specified in the key files. The program must use the key mappings to both encode and decode the...
  46. L

    Comp Sci Calculate 3 Largest Numbers in C++ with a while-loop

    C++-- while-loop Homework Statement calculate the 3 largest number of a sequence Homework Equations you ask the user to input a sequence of numbers, and enter the value 0 to stop entering numbers. c++ The Attempt at a Solution i managed to calculate the the maximum of the series of...
  47. Superposed_Cat

    C/C++ A good C++ compiler for windows 8

    I've tried downloaded three different compilers for c++ and none of them work, I have visual studio 2010 but c++ won't work on it. If someone could provide a link to a c++ plugin for it I would be soooo grateful. But anything is appreciated as long as it's free.
  48. Student100

    Comp Sci C++ allocating arrays dynamically.

    Homework Statement The problem is to dynamically allocate (closer to relocating) a dynamic class array in C++ based on the number of user inputs. We can't use vectors, malloc, realloc, or any such functions beyond new or anything simple like asking the user for how many questions they want to...
  49. Doofy

    Jobs for physics PhD's / At what point can you claim to know C++ ?

    Jobs for physics PhD's / At what point can you claim to "know C++"? I am a year away from graduating my HEP PhD and I'm thinking about what comes next. Postdoc is an obvious option, but the impression I get from this site and elsewhere is that it's a short-sighted one. I'm therefore thinking...
Back
Top