Programming: Principles and Practice Using C++

Category: Programming
Author: Bjarne Stroustrup
4.1
This Month Stack Overflow 5

Comments

by anonymous   2019-07-21

As an overly broad answer, you need to have an addressable context for the variable you're trying to use. What this really means depends on what you're trying to do and where in the code you're trying to do it. Are the variables global, members of another class, statically accessible. Check out CPlusPlus.com's tutorial on variables as a general reference if you're getting started and Stroustrup's Programming: Principles and Practice Using C++ if you're more of a book person.

In response to your clarification, this is modified from here:

int main () {
  CRectangle rect (3,4);
  MyWeirdShape wshapeA;
  cout << "rect area: " << rect.area() << endl;
  cout << "Weird Shape area: " << wshapeA.area() << endl;
  return 0;
}

We're within the main() method of the CRectangle class and create a new object of type MyWeirdShape and then call area() to get its size. If this were a static method we could skip the creation of the new object and just call MyWeirdShape::area().

by anonymous   2019-07-21

Search about tokenizing and grammar. A very nice example which fits the description of your problem is thoroughly presented in the book : http://www.amazon.com/Programming-Principles-Practice-Using-C/dp/0321543726 among other things.

This will not only allow you to solve this problem but it will also allow you to create a much more powerful calculator, taking into account things such as operator precedence, parentheses, curly brackets etc.

by anonymous   2019-07-21

There are two ways to do it. I wrote code in VS2017, 1.

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello World!\n";
    return 0;
}

2.

#include "stdafx.h"
#include <iostream>

int main()
{
    std::cout << "Hello World!\n";
    return 0;
}

for your reference https://en.cppreference.com/w/cpp/io/cout I highly recommend you https://www.amazon.com/Programming-Principles-Practice-Using-C/dp/0321543726

by anonymous   2017-11-06
You seem to be better off if you have a book and work on the examples: https://www.amazon.com/Programming-Principles-Practice-Using-C/dp/0321543726