I have a class Stack with a header file Stack.h which uses up another class with a header file Activity.h
I have a third class ActivityManager which uses up both the Stack and the Activity class.If I run the program and add in both Activity.h and Stack.h to the #include list I get a compilation...
There's stuff on here relevant to my day-to-day, which means I may also be able to contribute. I'm primarily focused on programming in C, C++, Python and Perl. Nothing now, just introducing myself - hello all!
TL;DR Summary: hh:mm format input
I'm solving this problem.
I've the algorithm ready.
Here's it.
But it's the easy part. The hard part is to code it specially in C++. (Not that I can do this in javascript).
How do I take say 14:30 as input(exactly that) and parse 14, parse 30 from it?
As I said earlier, I've already grasped basics of C++. Since my ultimate goal is to work in coding industry, for interviews, I need to prepare for algorithms and data structures, grind leetcode. Between C++ and Java, I choosed C++ because that was taught in our university.
I won't read the...
I am still not confident with C++
I don't think I should yet go to Data Structures and Algorithms yet because I am not very comfortable with C++.
I want a book that covers problems that require Object Oriented Programming to solve problems. It should have lots of such exercises.
Is there such a...
I am not understanding this code meaning
#include<iostream>
#include<cstring>
using namespace std;
class String
{
private:
char *s;
int size;
public:
String(const char *str)
{
size=strlen(str);
s=new char[size+1];
strcpy(s,str);
}
~String()...
Full code goes here: The goal of the program is to overload the extraction operator for cout.
#include<iostream>
using namespace std;class Time
{
private:
int hour;
int min;
public:
Time()
{
hour=min=0;
}
Time(int h,int m)
{
hour=h;
min=m...
How does "min" and "hour" get their values in this C++ code?
Full code here:
#include<iostream>
using namespace std;class Time
{
public:
int hour;
int min;
Time()
{
hour=min=0;
}
Time(int h,int m)
{
hour=h;
min=m;
}
Time add (Time t)...
Hello,
To keep my questions straightforward they are below.
How do I learn how to code Game Enemy AI in C++ from scratch and what are the top resources you recommend(Books, Tutorials, CD-Roms, Videos)?
How do I learn how to code Game Enemy AI in Assembly Langauge from scratch and what are the...
Hi PF!
Given a .csv file with the first row a name (string) and successive rows doubles, how can I read and manipulate this data in C++? Typically I just google these sorts of questions, but I'm seeing so many links. Do you have one that you recommend, or do you have a function you've written...
Hi PF!
I typically code in MATLAB. Here, if I run the following program
%% Section 1
x = 5;
y = 2;
%% Section 2
z = x + y;
everything works. But now let's say I wanted to change line 5 to z = x - y. In MATLAB this is simple: I can simply change line 5 and rerun section 2. Is there a way to...
I'm new to c++ and I have written a code. I need to plot using matplotlibcpp at matplotlib-cpp
However I do not know how to install it. I've tried vcpkg, but it doesn't work.
I want to be able to use it in my code when I do:
For example in Python, I would simply do the following to install a...
Summary: Problem with Euler Method in C++
Hello, I have a very difficult problem for me (a beginner in programming) how to make the version of the euler method presented in c ++ with the void, float functions, so that the program will calculate from the data that I enter during the program...
I am absolutely new to Polymer simulation. I am trying to understand the simulation by analyzing source code written by others.
Can anyone tell me what are the differences between the following three source code in terms of their objectives?
Monte-Carlo-simulation-of-polymers...
i only managed to draw a square and don’t know how to put circle pattern inside of it
#include <stdio.h>
int main()
{
int totalrowcol;
printf("Enter the number of rows: ");
scanf_s("%d", &totalrowcol);
for (int rowno = 1; rowno <= totalrowcol; rowno++)
{
for (int...
Hey! :giggle:
I am looking at the following:
a) Create a class QuadraticPolyonym that describes a polynomial of second degree, i.e. of the form $P(x)=ax^2+bx+c, a\neq 0$.The coefficients have to be givenas arguments at the construction ofan instance of the class. Implement a method...
Hey! :giggle:
I am looking the following exercise about C++.
(a) Create a class Matrix33 that describes a 2-dimensional $3\times3$ array of integers. At the construction of an element of the class allpositions of the array are initially zero (zero matrix). Implement methods to read and...
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 ?
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...
Hi
I have been literally studying back class overloading in the new C++ syntax( at least that's what I call). This is on class template that is very much like class. I want to verify whether my translation is correct or not. In the program, I have the constructor and operator[] with throw catch...
Hi
I want to know a little more about learning operating system. My grandson told me he is taking a class in operating system and the teacher use C and C++ mostly. He and his friends are in trouble because his school is Java based, none of them really know C++ and C.
Is Operating system...
I am stepping through the program and I actually wrote down the steps in comment each step the debugger step through. I have a few question I still don't understand. Here is the program:
//Matching catch handler with exception
#include<iostream>
#include<string>
#include<string_view>...
I am trying to run an Xcode project in c++ on a Mac Os. I started by creating new project, selecting command line tool options so that I may use c++ option and proceeded with completing the product name fields and the directory where to save the project on my Mac.
The default project that is...
This is a program from Gaddis that has two exception classes inside the Rect class. It is not clear for me how it works. Ivor book declares the exception classes as individual class, not inside another class. So I cannot compare and see what I missed in Gaddis book. Here is the program right out...
I followed the program from the book and it doesn't work. I simplified to show what's going on. I solve the problem and show in the second program. It's the good old cstring and the string literal again.
This is from the book, it doesn't work:
#include <iostream>
using namespace std;
int...
Hi
I just moved into Chapter 16 of Gaddis on Exception, Templates and STL. Seems like it jump a chapter. This is a partial sample from the book:
I have to complete the program as shown below but compiler doesn't like it.
#include <iostream>
#include <functional>
using namespace std;
int...
I am copying some program from youtube videos. This is the program I copied:
#include <iostream>
using namespace std;
class Base
{ int x;
public: Base() {} Base(int a) :x(a) { }
int get(){return x;}
void set(int a){x=a;}
};
int main()
{ Base b1; Base b2(10)...
I mentioned in another thread that I've been playing with a C++ class for 3D vectors, to review overloaded operators, constructors, etc. All those functions display output so I can follow which ones get called, and when. The class generates a serial number for each vector so I can tell them...
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...
I have no idea why the program got hung on cin.getline() in my program. cin >> works just find. Here is the program. It is the really scaled down version of my long program. I just deleted all the irrelevant things. The structure is defined in the header file.
I use debug to step through the...
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()...
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...
Question
Is there anyway to copy the content of a string into a C-String and make the length of C-String the right length of the string? This is the program I try to do, of cause this is NOT working. I don't know of any way to do this. I just want to run by you experts whether it's possible...
@sysprog posted this code for a nifty swap function that uses XOR in another thread in this section.
This put me in mind of a couple of swap routines that I did awhile back: one with references and one with pointers. Unlike the example above, both routines do use a third memory location. Rather...
I'm not a newbee to C++ but I've been out of the loop for a while.
I know it's discouraged, if not directly a no-go, to derive from STL classes. Something that has to do, if I remember correctly, with the STL classes having no virtual destructors.
It will work in the short run but may...
I have a quick question. The last 15 pages of chapter 11 is on Unions and Enumerators. Are they useful in real life programming? I can see some usefulness of Enumerators with well defined limited set of elements. The only reason for Union is to save a little memory.
But what do I know.
Today I found out that the textbook that I taught C++ out of for several years in the late 1990s and early 2000s is now available online for free. After it went out of print, the author (Owen Astrachan at Duke University) decided to make it freely available.
A Computer Science Tapestry, second...
I have a strange problem. I pass an Array[20] to a function. When I put cout << sizeof(Ar); (line 29 in the program) it only shows the length of one element ( 4bytes). BUT if I write cout << Ar[10]; (line 30 in the program) It will give me the correct number of the original idNum[10]. I tried a...
I have an error on this program I don't understand, it said stack corrupted around the 2 dimension array sales.
//2D sales in divisions in quarters.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int numDiv = 3;// 3 divisions
const int numQtr = 4; // 4...
To simulate the trayectories of solar systems around a black hole (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...
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...
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
Hi PF!
My question is easiest to show via the following input, the output, and my desired output.
input: x^2 + y^2 // CForm
output: Power(x,2) + Power(y,2)
desired output: pow(pos().x,2) + pow(pos().y,2)
I appreciate any help you can offer. Thanks so much!
Edit: for what it's worth, I'm just...
The program works as intended.
#include <iostream>
#include <ctime>
#include <cstdlib>
int coinToss ();int main ()
{
int tosses, result;
std::cout << "How many coin tosses? ";
std::cin >> tosses;
size_t seeder = time(0);
srand(seeder);
for (int i = 0; i < tosses...