"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...
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&...
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...
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 <<...
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...
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 <<...
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"...
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?
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...
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...
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 =...
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 <<...
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) && (?))...
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;
}...
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...
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...
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...
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() {...
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...
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...
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...
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...
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...
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...
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 ...
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...
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...
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)...
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...
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...
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) + (...
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...
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...
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...
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...
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
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...
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.
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...
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...
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.
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...
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...