Hi,

I dont know much about Standard template library(Vectors, Lists, Deque).
I want to do one Program which is as follows.

Write a program to create a data bank which holds the operator and operands of arithmatic/relational/bitwise(etc.,) operations. (Use STLs)
The no. of operand fields(input and output) is variable depending on the kind of operation.

Details:
The number input and ouput fields is unpredictable(ie. it may vary depending on the “operator” field).
For eg.,
AND operation takes 2 inputs and one output( a = b & c),
but
NOT operation has one input and one ouput ( x = !y).

Dev. Platform:
Visual Studio 6.0(if possible)
Visual C++

Note:
1) The number of fields may increase or decrease dynamically.
2) There is no limit upto how many fields it may increase.

Could any one please help me to do this. I dont have idea about standard template libray. sp please get me some tutorials or get me the code for this program

Dani AI

Generated

— a simple, practical approach is to model each record as an Operation object that stores the operator token plus dynamic lists of input and output operands, then keep all Operations in an STL container. For most uses std::vector<Operation> is easiest and fastest. Use std::list only if you expect many insertions/removals in the middle; std::deque is handy when you need fast push/pop at both ends. As suggested, start with this small framework. ’s BST comment is useful only if you need ordered, keyed lookup; otherwise it adds unnecessary complexity.

A minimal, pre-C++11-friendly design:

#include <string>
#include <vector>
#include <iostream>

struct Operation {
    std::string op;
    std::vector<std::string> inputs;
    std::vector<std::string> outputs;
};

// create, push_back, iterate (see post body for usage)

Key practical tips:

  • Represent operands as strings initially (variable names or literals). If you later need types (immediate vs register) add a small enum or a tiny struct Operand { Kind kind; std::string value; }.
  • If you need to find the operation that produces a variable quickly, maintain a std::map<std::string, size_t> mapping output name -> index in your vector.
  • Use reserve() on vectors if you can estimate sizes to avoid repeated reallocations.
  • On Visual Studio 6.0: the STL implementation is old and lacks C++11 features (no range-for, emplace_back, etc.). The shown pattern (plain push_back, indexed loops) is compatible, but consider using a modern compiler if available.

For concise references see the std::vector and std::map documentation: std::vector reference and std::map reference.

Recommended Answers

All 2 Replies

Well start out writing the program framework. and next you can ask where you need help.

A BST would be a better data structure for your homework.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.