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...
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...
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...
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] ...
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...
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 ++
{...
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...
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...
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...
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...
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...
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 =...
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...
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...
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...
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...
#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<<...
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...
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: ...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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>...
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...
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...
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?
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...
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 {
...
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...
[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
:)
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.
[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...
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.
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...
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...
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...
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()...
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...
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...