C++ ::  Tree Data Structure To Represent Category And Subcategory Of Products

Jan 15, 2015

Given a product category and sub­category representation:

a. Come up with a tree data structure to minimally (in terms of storage) represent this
b. Write a program to convert the given representation (shown in example below) to this
c. Write a function to output the tree structure in a nice human readable format

Note:
a. There can be any number of levels of depth
b. Rows may be repeated in input, but need to feature only once in the final tree.

Example category list (read this input from a file):

everything else|office supplies
electronics|video games
electronics|video games|accessories
electronics|video games|accessories|headsets
electronics|video games|accessories|flight controls
electronics|video games|accessories|joysticks

View 5 Replies


ADVERTISEMENT

C++ :: How To Create Tree Data Structure With Boost

Oct 1, 2013

There seems to be lacking support for tree data structure. You have to implement it yourself?

View 2 Replies View Related

C :: Create A Structure To Store Information About Products For Sale

Apr 29, 2013

I am using Dev C++ compiler on Windows 7 and was programming a piece of code that is supposed to do the following -

Create a structure to store information about products for sale in a store. It should store information about the product name, the price, and the product number and then create an array of products called Inventory. Add five products to your inventory.

But for some reason, which is unknown to me, I always seem to get a compiler error. And this is what i have so far -

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct product{
char name[30];
int product_number;
double price;

[Code] ....

View 4 Replies View Related

C++ :: Linked Structure For Binary Tree

Dec 16, 2014

So i am implementing the class LinkedBinaryTree and i am aplying "Depth and Height" and "A linked structure for binary tree".

#include <iostream>
using namespace std;
// InspectableContainer
template <typename Object>
class InspectableContainer {
public:
int size();
bool isEmpty() const;

[Code] .....

View 4 Replies View Related

C++ :: Creating Tree Like Structure Using Linked List

Apr 25, 2014

How would I go about creating a tree like structure using linked lists, I am thinking of making a rubix cube solver program, what I want to do create nodes that each do one operation like turn left, right, up, down but I dont know how to go about starting this.

View 2 Replies View Related

C++ :: Category And Constant Storage

Mar 14, 2013

I have a class that I'm going to use to store a category. Right now there are seven options, but there is the potential for a whole lot more in the future. So I started off by storing an integer as the private member. I then used static constants to define the numeric values to represent each category, then a set of static constant strings that corresponds to those numbers in case I need their actual names. Finally I set up some static functions to convert between the integer value and the string, and vice versa.

I'm not sure if this is the best way to go about this. For one it makes the categories names and designations unchangeable. I thought that storing them in a file would be a better option, but then i needed a container that is the equivalent of a constant.

I thought of defining a class to contain an int and the associated string. It would be designed so that it can only be initialized with both items. Then provide no functionality to change the contents. So I've basically created my own constant.

View 4 Replies View Related

C++ :: Std Container Iterators - Category?

Jun 15, 2014

When using an iterator with a std container (list / vector etc) sometimes it's possible to modify the container (e.g. delete an item) yet still carry on using the iterator - whereas in other cases, modifying the container immediately invalidates any open iterators on it. Is there an easy way to know which containers fall into which category? (or does it vary from one compiler to another?)

View 2 Replies View Related

C++ :: Program That Takes Sum Of Products And Generates Sum Of Minterms

Nov 28, 2013

Write a C/C++ program that reads a boolean expression in sum-of-products form and generates the sum-of-minterms form (canonical form). Use single letter to represent variables. The following symbols will be used to represent operators: NOT: ~, AND: *, OR: +. Other operators won't be used.

Examples of execution:
number of variables: 2
SOP expression: ~A+B
output: ~A*~B + ~A*B + A*B

number of variables: 3
SOP expression: x*y*z + ~x*~y + y*~z
output: x*y*z + ~x*~y*z + ~x*~y*~z + x*y*~z + ~x*y*~z

View 3 Replies View Related

C :: Input Matrices Dimensions - Calculate Elements Of Products

Nov 14, 2013

This is my code and it's not giving me the right output

Code:
#include <stdio.h>
int main() {
int dim;
int i, row, col;
// inputting matrices dimensions
int M0, M1, M2;

[Code] ....

The output should give me this:
Input 2
Correct Output 2 5 4 10

View 10 Replies View Related

C :: Binary Search Tree - Struct Data

Oct 24, 2013

I was working with binary search tree and came up with the solution:

Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct data {
int x;
struct data *left;
struct data *right;

[Code] .....

View 6 Replies View Related

C++ :: Find Minimum Data Of Binary Tree?

Mar 24, 2013

I want a recursive function that returns a pointer pointing to the node which has the minimum data in the binary tree.

That's what I wrote:

struct CP {
int data; // data of the node
CP * left; // pointer to the left subtree
CP * right; // pointer to the right subtree

[Code]....

It can only find one side of the binary tree.

View 8 Replies View Related

C :: How To Write One Binary Tree Function To Sort The Data

Dec 2, 2014

The Problem You are part of a company writing a spreadsheet program. As you know, spreadsheets can be sorted on any column. You're part of the project is to write one binary tree function to sort the data [Hint: use different fields when inserting nodes in the tree.] and a second function to list it in either an ascending or descending sequence. [Note: Each of these functions may actually need to be a set of related functions.]

For sample data you will have a disk file containing information about Shakespeare's plays. Your first function should create a tree based on the sort selected by the user and the second function to display the data in the sequence selected by the user. Regardless of the column being sorted, data in individual records always be displayed in the same line of the output.

Input : Each record will contain the following information: First Performed 9 characters Printed 5 characters Title 26 characters Type 7 characters

Output : Tabular output should be aligned in columns with two spaces between each. All columns should have headings. It should be sorted on the column specified by the user.

Example (This sample data provided so you can test your program.) If the data is:

1595-96 1600 A Midsummer Night's Dream Comedy
1594-95 1623 Two Gentlemen of Verona Comedy
1596-97 1623 King John History
1597-98 1598 Henry IV, Part 1 History
1611-12 1623 The Tempest Comedy
1602-03 1623 All's Well That Ends Well Comedy

[Code]...

Source: [URL]...

Possible outputs are

1 - for a sort by title: First
Performed Printed Title Type
--------- ------- -------------------------- -------
1595-96 1600 A Midsummer Night's Dream Comedy
1602-03 1623 All's Well That Ends Well Comedy
1606-07 1623 Antony and Cleopatra Tragedy
1599-1600 1623 As You Like It Comedy

[Code]....

2 - for a sort by first performed: First
Performed Printed Title Type
--------- ------- -------------------------- -------
1590-91 1594? Henry VI, Part 2 History
1590-91 1594? Henry VI, Part 3 History
1591-92 1623 Henry VI, Part 1 History
1592-93 1623 Comedy of Errors Comedy
1592-93 1597 Richard III History

[Code]....

View 1 Replies View Related

C Sharp :: Display Data In Richtext Box In Tree Format?

Jan 31, 2013

I want to display my data in rich-text box in the tree like structure,i fetch the data from the data base MSACCESS & i want to print it on my rich-textbox, what can i do ?

exampale is :-A
|
|__A1
| |_A1_1
| |_A1_2
|__A2
|__A3
|_A3_1
|_A3_2

like this in rich textbox

View 1 Replies View Related

C++ :: Functions Without Parameters - Compute And Print Total Number Of Products For Company

Mar 27, 2013

Summary: 6 companies have a product in 5 different warehouses. Each company is identified by a positive ID number and each warehouse is identified by a number (1 for the first, 2 for the second,…)

Object: the object of this assignment is to write a C++ program which asks the user to enter a company ID number, and the number of products in each of the warehouses. It then computes and prints the total number of products for that company

If the total number of product is less than 100, it prints the message “place a new order”

Input: for each company, its ID, and the number of products in each warehouse with appropriate prompt messages.
Example: Enter company ID number: 101
Enter number of products in warehouse #1:30
Enter number of products in warehouse #2:60
Enter number of products in warehouse #3:0
Enter number of products in warehouse #4:5
Enter number of products in warehouse #5:27
The total for company 101 is:122

Output: for each company, the total number of product, and the message “place a new order” if the total number of product is less than 100.

Method:
1. Define global variable, int total_prod to hold the total number of products for a company
2. define the function void compute_total() that uses a loop to read the number of the products in all warehouses for one company, computer the total number of products and store it into the global variable total_prod.
3. Define the function void new_order() that determines if a new order need to be placed as follows: if the total number of products (in the global variable total_prod) is less than 100, it prints the message “place a new order”
4. Your function main does the following in a loop:
- read a company ID number
- call function compute_total() to read the number of the product in all warehouses for that company, and to compute their sum
- print the total number of the product for that company with an appropriate message
- call the function new_order() to determine if a new order need to be placed.

View 17 Replies View Related

C :: Scope Of A Data Structure

Oct 9, 2013

how to solve this undeclared error when compiling this code. I assume it has something to do with scope.

C code - 47 lines - codepad

Code:

#include <stdio.h>
int main(void) {
struct bank_account {

[Code].....

View 3 Replies View Related

C++ :: Asymmetric Data Structure

Mar 18, 2013

I am trying to create an structure of data with following elements:

struct stest {
std::vector<int> na;
std::vector<double> nb;
std::vector<double> va;
std::vector<double> vb;
std::vector<double> vc;
std::vector<double> vd;
}

I would like to modify the composition of this struct, so that I can create a special data structure by

vector<stest*> data_test;
for(int i = 0; i < 10; i++)
data_test.push_Back(new stest);

within this structure, I have: only one na and one nb, but ten groups of combination of va, vb, vc, vd that I can access by pointer, which means na, nb are independent but still inside of the structure.

View 2 Replies View Related

C++ :: Two Dimensional Map - Data Structure

Apr 4, 2013

I'm currently having the following data structure:

typedef struct {
int a;
int b;
} S;
<vector <vector<S> > v;

Now I also have different pointers that can be set in connection with one instance of the above shown vector. Therefore I was attempting to work with a map:

map<p*, <vector<vector <S> >, vector<sI> > m;

However, it seems like it doesn't work that way. Therefore I tried the following:

map<p*, map<<vector<vector <S> >, vector<S> > > m2;

With this attempt I do now, however, get another mistake here, that [] cannot be used here:

S s;
m2[p][0].push_back(s);

View 13 Replies View Related

C++ :: What Data Structure Does A Vector Use

Dec 14, 2013

Does it use Linked List or Dynamic Array?

I want to know this because if I happen to want to use a lot of insertions and deletions then it is more efficient to make use of Linked List instead of Dynamic Array.

While, if I happen to want to just access random parts of the Array, then Dynamic would be more efficient.

I want to make a 2D game using SDL engine and I need to check whether or not an object is colliding with a list of other objects. (because there would be more then one objects on the map.)

Since I would simply be accessing each object sequentially to check whether or not the object is colliding with another the object in question, and since any of those objects could "die" and be deleted at any time, it makes more sense to use Linked List then a Dynamic Array.

View 8 Replies View Related

C/C++ :: How To Use One Structure Data In Other Structures

Jul 2, 2014

I created one structure and the created structure is using in few more structures, but i did not get the proper data.

typedef struct _MSG_HEADER{
//MESSAGE_HEADER 40 bytes
short iApiTcode;
short iApiFuncId;
int LogTime;
char AlphaChar[2];

[Code]...

My requirement is have to fill the MessageHeader structure & we can use that header in all the structures entire program.

View 3 Replies View Related

C++ :: Vectors With Structure - How To Add Data

Nov 26, 2014

I have two structs like below,

struct SP {
string sp1;
string sp2;
};
struct SL {

[Code] ....

How to add data to slVect ?

View 6 Replies View Related

C++ :: Using Custom Class For STL Set Data Structure

Oct 27, 2014

When we want to use custom classes for the STL set data structure, how to do it?

I look around and see people passing comparators, overloading operator(), and also overloading operator< in the class itself.

Which one's the idiomatic c++ way?

View 1 Replies View Related

C :: How To Store Data Structure Into 2D Array

Mar 22, 2013

I have this data store into a data structure.

i j x y w h w*h
0 0 0 0 9 11 99
1 0 0 11 9 10 90
2 0 0 21 9 11 99
0 1 9 0 8 12 96
1 1 9 12 8 7 56
2 1 9 19 8 6 48

[Code]...

Code:

struct data {
//Here
/*! horizontal position */
int x;
/*! vertical position */
int y;
/*! width */
int w;
/

[Code]...

data and then i have an array /*! it contain group_id of each data line*/ int group_id[16]={0,0,0,0,3,3,1,1,1,3,3,2,2,2,2,1}; I never worked with 2D array before. My problem is that i want to create a 2D array of that data for example if i write data[j][i].. It will give me the reference/value of all data lines that belongs to j column, and same with group_id[j][i]. I don't know how i can store these structure vaules in this like 2D array.

View 2 Replies View Related

C++ :: Corporate Data Sales Structure

Nov 20, 2013

Corporate Data Sales

Write a program that uses a structure named CorpData to store the following information on a company division.

Division Name(North, South, East, Or West)
First quarter sales
Second quarter sales
Third quarter sales
Fourth quarter sales
Total annual sales
Average quarter sales

Include a constructor that allows the division name and four quarterly sales amounts to be specified at the time a CorpData variable is created.

The program should create four variables of this structure, each representing one of the following corporate divisions: North, South, East and West. Each variable should be passed in turn to a function that calculates and stores the total annual sales and average sales for that division.

Once this has been done for each division, each variable should be passed in turn to a function that displays the division name, total sales, and average sales.

Here is my code:

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
struct CorpData {

[Code] ....

View 1 Replies View Related

C++ :: Data Structure - To Check If A Set B Is A Subset Of A Or Not

Feb 9, 2013

To check if a set B is a subset of A or not. Which data structure to be used to store set A for quicker response(linked list/hash map)? What if I want to check intersection also?

View 1 Replies View Related

C++ :: Implementing Stack Data Structure As ADT

Mar 7, 2014

So I've been working on implementing a stack data structure as an ADT, the program compiles, but when I try and push elements on top of the stack, for some reason the stack is full.

#ifndef H_stackADT
#define H_stackADT
template <class Type>
class stackADT {
public:
virtual void initializeStack() = 0;
virtual bool isEmptyStack() const = 0;

[Code]...

View 4 Replies View Related

C++ :: Data Structure - Program Using Stacks

Nov 3, 2013

Given a set of different types of paired symbols; determine whether it is balanced or not (the opening and closing version of each type are paired correctly). Any other type of characters may appear in the input will be neglected.

For example:
(**(*[*])****) is balanced, also [{}**[]**()]** is balanced. But ((*{*)*}) is unbalanced as well as [()***[]***{*(*)}.

Write a C++ program that requires a string containing and expression as an input from the user and check for balanced bracket pairs using stack data structure.

Here is my code which give me nothing when I run it.

#include <iostream>
#include <string>
using namespace std;
class CustomStack {

[Code] ....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved