Topics about c++ - 78 Discussions, Page 1

  1. B

    C/++/# Why are struct use for linked list and classes used for binary tree?

    Why are struct use for linked list and classes used for binary tree. honestly what is the different between a class and a struct? I have a teacher one tell me that a class was a struct on steroids. but what does that really mean ?
  2. Z

    C/++/# Wrong solution order using Runge Kutta 4

    Hi, I'm trying to simulate a 3-body problem with a star at the center of reference system and 2 body orbiting around it using Runge Kutta 4. The 2 bodies perturb each other orbits gravitationally, so my ode system is actually a coupled armonic oscillator and I evaluate the solution of both...
  3. A

    Comp Sci Template for the STL

    in .h file I write like this: namespace board{ template <class T> class BAdapter : public AbstractB{ public: BAdapter(); BAdapter(int x){ x=6; setSize(x); } virtual void setSize(int receivedSize){...
  4. S

    Converting State Vectors to Keplerian Orbital Elements for Binary Objects

    Homework Statement:: I'm working on a personal project to convert objects from a simulation using state vectors for position and velocity to Keplerian orbital elements (semimajor axis, eccentricity, argument of periapsis, etc.). However, the equations I am using do not calculate the...
  5. A

    Comp Sci Class and vector

    I am now learning C ++ and trying to learn class and vector. I'm trying to write code, but I got an error. this is my class and enum class: enum class state: char{ empty='.', filled_with_x='x', filled_with_o='o'}; class class1{ private: class class2{ class2()...
  6. A

    Comp Sci Cin.ignore remove first character

    if(count%2==0){ //for user 1 cout<<"User 1"<<endl; cout << "Please enter your move: "; cin.ignore(); getline(cin,str); //do something } else if (count%2!=0){ //for user 2 cout<<"User 2"<<endl; cout << "Please enter your move: "; cin.ignore(); getline(cin,str); //do something...
  7. A

    Comp Sci Generate random numbers in C++

    I want to generate random numbers in C++. I do not want to use C library function (`<cstdlib> <ctime> (time.h)` ) and class. So I cannot use `rand()` function in C. I want to generate random integer numbers and I guess I can use `<random>` library in C++11. How can I use this generate random...
  8. Adec

    Comp Sci Galaxy simulation with the velocity Verlet algorithm

    To simulate the trayectories of solar systems around a blackhole (i.e. a galaxy) I have 3 classes in C++: cSystem, cBlackHole and cGalaxy. cSystem assigns initial values of position, velocity, etc to a solar system. cBlackHole does the same but just for the black hole. And cGalaxy mixes...
  9. E

    C/++/# C++ Program Suddenly Ends after Reading Huge Data

    I have written a C++ code in Visual Studio 2019 that requires an input tab-delimited text file and outputs a text file that is also tab-delimited. The data within the text file are stored in a vector and then it will perform calculations, whose results will then be written in a text file as...
  10. Vick

    C/++/# Need help with C++ code

    I'm not at all C++ literate, but I need to understand what a C++ code is doing for a math problem regarding the Stieltjes polynomials. Especially, I want to know what is happening to the "num" and "den" in the code; the code is in this link: Stieltjes
  11. B

    Second programming language to get under the belt: python vs C

    Hello everybody, I am a master student in Theoretical Chemistry and I am working in the DFT realm. Both TDDFT and DFT applied to extended systems (eg. using QUANTUM ESPRESSO). Of course I work with these softwares from a end-user point of view, not as a developer. But anyway, even if some of...
  12. S

    Loops to compare many rows between 2 worksheets in C#?

    Hello All, I took it upon myself to create a tool for my job that xref 2 excel worksheets on 2 different workbooks. Customers send us parts and they're wanting the leadtimes for them. We have a weekly report that has all part numbers with their leadtimes. My goal is to create a GUI in C# that...
  13. adamaero

    Compiles, and motor driver shields work individually--but not together

    I don't have a debugger yet, but my company is getting one... In the mean time, I've been un/commenting out parts of Mbed's code. Their Hello World program is available from this website, and it can be used directly in their online IDE by clicking "Import Program"...
  14. JayZ0198

    Multipurpose software that keeps C, Python, DSP, ... in the same file

    I’ve been looking for a certain type of software that can host programming (preferably C or Python) and other process that I’m going to need such as DSP, DSP filters, diagrams (3D graphs, charts,…), and text editing within the same file. It’s mainly so that I can incorporate and use each one...
  15. J

    Comp Sci How do you read two files in the same program in C++?

    My matrix text files can vary from 1x1 to 10x10 (Another file will be given when the code gets tested but it's all square matrices) I'm stuck here. #include <iostream> #include <fstream> #include <string> using namespace std; int main() { const int MAXI = 10; int x, y, z...
  16. J

    Comp Sci C++ How to read char + number

    Hello, the text file I'm trying to read is formatted as below: x y z point1 number number number I have used getline to discard the first...
  17. J

    Comp Sci C++ File Output

    I have computed the total length of a 3D triangle and its area. The code is shown below. I want to use file output instead of cout. The file name, cw2task1output, was just given as part of the task, in this case should I make an empty text file named cw2task1output then attach it to the resource...
  18. davidfur

    C/++/# MPI parallel code speed-up sucks

    Hey guys, I parallelized my code, written in C++, with the MPI library. Unfortunately, the speed-up I get saturates at x6, with increasing number of cores. Whereas, in theory, the speed-up should really be nearly linear. To understand where the bottlenecks come from, I drilled down the code to...
  19. M

    Dynamic Programming - Restoring white space between words in a file

    All the white space among words in a text file was lost. Write a C++ program which using dynamic programming to get all of the possible original text files (i.e. with white spaces between words) and rank them in order of likelihood with the best possible runtime. You have a text file of...
  20. J

    Comp Sci C++ Opening a txt file using argc and argv

    Homework Statement I have a complete code that calculates distances between point 1(x1,y1,z1) and other points(from 2nd up to more than 100) and the nth point that results in minimum distance and the minimum distance between point 1 and nth point. The code is below. The code is 100% correct...
  21. J

    Comp Sci C++ Reading a data file

    Homework Statement I have successfully opened and discarded the headers. Then I calculated the distances between point 1 and others and the minimum distance as well. However, I am not sure how to make the code work for more than 4 points. The attached text file is what I am trying to read and...
  22. J

    Comp Sci C++ program to read an input file with multiple headers

    Homework Statement Write a program that can read an input file with a simple header. The Attempt at a Solution #include <iostream> #include <fstream> using namespace std; int main() { ifstream inFile;"Data"); //Check for error if ( {...
  23. YoungPhysicist

    C/++/# Using cin like scanf()

    if I want to read to integer a and b and they are in a formation of [email protected], I CAN SIMPLY USE scanf(%[email protected]%d,&a,&b) to read the input. But how should I do that in c++(with cin)?
  24. SchroedingersLion

    C/++/# Setting up an FCC lattice in a simulation

    Greetings, for a Monte Carlo simulation of N hard spheres, I want to set up the initial configuration as a fcc lattice. I am thinking about how to do it most efficiently. Here is the lattice structure: The 3 lattice vectors, each one pointing to a different type of the 12 nearest neighbors...
  25. B

    0s and 1s Array problem

    Homework Statement A house has n x m rooms (n and m natural numbers, n>=2 and m>=2) and is represented as a 2 dimensional Array with n rows(0 to n-1)and m columns(0 to m-1).The room at line i( 0 <= i <= n-1) and column j ( 0 <= j <= m-1 ) is identified by the pair of numbers (i,j).All rooms...
  26. D

    Comp Sci Working with classes and vectors in C++

    Homework Statement Write a BinaryTree Class using these specifications: A Class Node represents a standard node of the tree with fields and a constructor like given below: int start, end; const Complex* value; //I will provide more information about Complex later because that was the...
  27. R

    Comp Sci Velocity Verlet applied to solar system with C++

    Homework Statement Hello, I am attempting to use the velocity Verlet algorithm of integration applied to the solar system in c++. My goal is be able to use the outputted position components in a plot to see if the trajectory of my object is elliptical/parabolic/hyperbolic resulting from the...
  28. D

    Algorithm to matrix product MSR format

    Hi everybody, I'm writing some algebra classes in C++ , Now i'm implementing the modified sparse row matrix , I wrote all most all of the class, but I didn't find the way saving computing time to perform the product of two Modified sparse row matrix .. if you don't know it you can read in the...
  29. D

    C/++/# Question about a specific class method in C++

    Create a class DecimalN which holds decimal numbers using dynamic arrays. Implement a constructor DecimalN::DecimalN(char* decimal) so that it can be created like for example DecimalN number("23.5698"). Create two class functions (methods) that given the number n it shift the number n places...
  30. D

    Comp Sci Using a custom constructor in a C++ class

    Homework Statement I am quite new to C++. I have completed my C course and am now taking a C++ course at my college. The first problem i encountered is with classes and custom made constructors. In the first part of the problem I am supposed to create a class with a field which is a dynamic...