C++ :: Creating Binary Tree Program - Allow User To Input Data Types

Apr 23, 2013

In class we were asked to create a C++ BTree program that would allow a user to input the following data types and then store said data in a .txt file:

0. ID 8 bytes

1. First name 30 char

2. Last Name 30 char

3. Street Address one 30 char

4. Street Adress two 30 char

5. City 30 char

6. State 20 char

7. Zip 10 char

8. Country 30 char

(I'm not particularly asking for full code, pseudo code would also be great). I had a great deal of my work done, unfortunately, the computer I was working on crashed, corrupting my files.

View 4 Replies


ADVERTISEMENT

C :: Binary File Write By User Input Then Printing Binary File Data Out

Dec 6, 2013

Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.

Code:
#include <stdio.h>
int main() {
int a[3][3],i,j;
float determinant=0;
int x;
FILE *fp = fopen ("file.bin", "wb");

[Code] .....

View 6 Replies View Related

C++ :: Binary Search Tree Used With User Defined Class

Nov 29, 2014

I am working on a program that uses a class I created called Student. I want to be able to add different students to a Binary Search Tree, and use the student's gpa (grade point average) to compare students with each other and place them in the correct location in the Tree.

Student class:

#ifndef STUDENT_H
#define STUDENT_H
#include <string>
#include <iostream>
#include <iomanip>
class Student{
friend ostream& operator<<(ostream& out, const Student& stu);

[Code] ......

View 3 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/C++ :: Binary Search Tree Program - Segmentation Fault Error

Mar 21, 2014

I'm writing a binary search tree program and I got it to compile but as soon as I input something it returns a "segmentation fault error" . I suspect the issue with the code is withing my `add` function.

template<typename T>
void BinarySearchTree<T>::add(T value) {
if (m_root == nullptr) {
Node<T>* node = new Node<T>;
node->setValue(value);
m_root = node;

[Code] ....

View 6 Replies View Related

C++ :: Looping - Input Numbers Until User Types 0 Then Output Product Of Non Zero Numbers

May 1, 2014

How to do the problem below using loop?

Input numbers until the user types a 0, then output the product of the non 0 numbers: e

E.g., if the user types 2 4 6 0, the program should output 48

View 3 Replies View Related

C++ :: Dynamic Password Guessing Program - Conflict Between Data Types

Mar 17, 2015

I'm trying to develop a deeper knowledge of how loops work (and what better way todo that than a dynamic password guesser). My main problem lies with the conflict between data types, as I try to point to a char at a specific index position of the password guess.

See in my code (at line 57):

Code:
#include <iostream>
#include <iterator>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
string AlphaNum("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");//62 possible characters
int size = AlphaNum.length();//should be 62

[Code] ....

This is annoying, because strings are arrays of characters themselves.

View 14 Replies View Related

C/C++ :: Find Maximum Element From A Tree (not A Binary Tree)

Oct 31, 2014

I want to find maximum element from a tree (not a binary tree ) ???? ...using c language...

View 1 Replies View Related

C++ :: Class To Store Nodes Of Tree - Converting Between Types

Jun 4, 2013

I'm writing a class to store a tree I have a small issue.

I have a class which stores a node of the tree, something like this:

template<class T>
class node {
private:
(stuff regarding parent node and child nodes);
T __data;
public:
// more stuff (constructors and utility functions) here
};

And I want to I want to be able to do the conversion T(node<T>) implicitly. For example, I want to be able to do this:

node<int> myNode;
myNode=5;
myNode+=10;
myNode*=9;
int x=int(myNode/4);
cout << x+myNode;

And this:

class myClass {
int x;
int y;
void print () {cout << x << ' ' << y << endl;}

[Code] ....

How could I achieve this?

View 2 Replies View Related

C++ :: Creating A Loop To Allow User To Choose To Return To Beginning Of Program Or Quit

Apr 6, 2014

I am currently having problems creating a loop that will allow my user to choose to return to the beginning of the program or quit.

#include <iostream>
using namespace std;
int main() {
int j;
do {float a;
cout << "+----Welcome to Basic Operations----+
| Select Your Operation |

[Code] .....

I have not yet finished designing the interface for a couple of the operations, but right now i am hung up on trying to return to the beginning. I believe it is because the j was defined inside do and isn't carried out of the do statement for while.

View 13 Replies View Related

C/C++ :: Creating Program That Allows User To Enter Unknown Number Of Income / Expense Amounts

Feb 21, 2014

I'm trying to create a program that allows the user to enter an unknown number of income and expense amounts. The program has to us see a while loop and display the income total, expense total, and total profit or loss. I've got it really close, but I'm doing the loop wrong. It counts the sentinel value (-1) towards the total, instead of just ending like it is supposed to.

#include <iostream>
using namespace std;
int main() {
//declare variables
double incomeInput;
double expenseInput;
double incomeTotal=0;
double expenseTotal=0;

[code]....

View 5 Replies View Related

C++ :: Set Width Of Data Values Which User Will Input

Sep 24, 2014

I am trying to set the width of the data values which the user will input when using the program but I don't know how to get it to show the values when I tryto set the width of the variables in a nice column .

//Programming Assignment 4

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
int main() {
double q1r1, q2r1, q3r1, q4r1;
double q1r2, q2r2, q3r2, q4r2;
double q1r3, q2r3, q3r3, q4r3;

[Code] ....

View 2 Replies View Related

C++ :: How To Stop Outputting Data Based On A User Input

Sep 27, 2013

how to stop outputting data based on a user input. The text file is as follows:

1. a
2. b
3. c

and the code I'm using is as follows:

int main (){
string line;
int search;
cout << "Enter a number from 1-3" << endl;
cin >> search;
search++;
ifstream myfile ("example.txt");

[Code]...

What I want to do is to just output number 1 (the whole line) if the user enters number 1. However, I get an error on the second condition w/c is the "&& line!= search"

View 1 Replies View Related

C++ :: Looping User Input For Specific Data Type

Apr 17, 2015

Here's my code so far:

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int dayNumber = 1;

[Code] ....

The code, when run, prompts the user to input an integer like this:

Code:

Day 1
Andy :>12
Bill :>7
Charlie :>15

Day 2
Andy :>5
Bill :>25
Charlie :>14
.
.
.
etc.

Ok, so the code prompts the user to enter an integer for each of the 3 persons and then increments the "Day" and so on... When the user enters a negative value (-1, -2, etc.), the loop is broken and the program ends. Alright, everything is hunky-dory so far. 2 things which I can't figure out.

1. when the user doesn't enter anything and just hits return, the cursor drops a line and is still awaiting an input but doesn't show the prompt "Andy :>", for example. How can I get it to repeat the last prompt when the user doesn't enter anything? Like:

Code:

Day 1
Andy :>
Andy :>
Andy :>12
Bill :>25
Charlie :>15
.
.
etc.

2. When the user enters a letter or a special character, the program blows up. How can I correct this?

I've tried changing the data type for the variable used for the input, tried using getline, get, etc. With my current beginner knowledge, I'm missing something. So how can I get this to work?

The program should allow only integers to be entered, while allowing a negative number to trigger the loop to break or the program to end, and while re-prompting the last person if the user entered an invalid input.

View 13 Replies View Related

C++ :: Input Data Of Object From User And Then Insert It In Linked List

May 16, 2013

Error:
--------------------Configuration: nc - Win32 Debug--------------------
Compiling...
cv.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/nc.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

nc.exe - 2 error(s), 0 warning(s)

Compiles with 0 error but on running 2 Errors appear.

I'm Inputting data of an object from user and then inserting it in the link list.

#include <iostream>
//#include <fstream>
using namespace std;
#define LEN 100
////////////////////////////////////////////////////////////////////////////////////////////////////
class employee{

[Code] ....

View 1 Replies View Related

C++ ::  Binary Program / How To Eliminate Leading Zeroes Of Input

Nov 18, 2013

I am looking to eliminate the leading zeroes of the input. The format has to stay the same and output must be as hinted in formatting.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void process(ifstream& infile, char&ch, int&dec, int&c, int&w);
int main(){

[code]....

View 2 Replies View Related

C++ :: Create Binary Search Tree Template To Be Used To Create AVL Tree

Feb 10, 2013

For my data-structures class, I am attempting to create a binary search tree template to be used to create an AVL tree. I've written a Generic_Tree template for the BST to inherit from, and before I jump into implementing the AVL tree I'm testing the BST member functions. Everything was compiling fine until I added the BST insert() function. Now, I'm getting the following error message from my linker:

undefined reference to 'BST<void>::insert(int, void*)'

Stemming from the call in main line 16.

my makefile compiles with:
g++ -Wall -g Generic_Tree.cpp BST.cpp barfing.cpp main.cpp

Generic_Tree:

template < typename NODE_DATA, unsigned MAX_KIDS >
class Tree {
protected:
struct NODE {
NODE_DATA* contents;
Tree* child[MAX_KIDS];
Tree* parent;

[Code] ....

I'm use to c and havn't used classes or templates before (except for declaring instances of them). The whole syntax is mystifying to me,.

View 4 Replies View Related

C++ :: User Input Data About Percentages To Calculate Final Grade - Addition Error?

Sep 15, 2014

I am trying to code a program that takes in user inputted data about percentages and using it to later on calculate a final grade. 4 percents are inputted, for Assignments, Midterm1, Midterm2, and Finals. If the percents dont add up to 1 (i tell the user to enter the decimal value) I set up and if statement to catch it and end the program. Except that if i type in

Assignments = .3
Midterm1 = .3
Midterm2 = .3
Finals = .1

the program doesn't recognize that they add up to 1. Heres the relevant portion of my code [URL] ....

Here's some examples of how it works [URL] ....

And heres what i dont understand [URL] ....

Why is it saying .3 + .3 + .3 + .1 != 1 when .1 + .3 + .3 + .3 == 1?

View 1 Replies View Related

C :: Compare String User Input With A String In Binary

Jul 14, 2014

I have problem with string compare. I want to compare the string user input with a string in binary. And I don't know how to do it. Problem in function login();Here is the code: And you also can download file in attachment too..

Code:

#include<conio.h>#include<dos.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
char nsb=1;
char ch, password[20], passlogin[20], inputpass[20], checked[20];
FILE *fp;
}

[code]....

View 1 Replies View Related

C :: Program To Read Binary Data And Print It - File I/O Error

Mar 14, 2013

Objective of this program is to read binary data from a file and print it.

Code:
#include <stdio.h>
void readFile(void);
int main(){
readFile();
return 0;

[Code] .....

But When I Run This Code First It Print "Error." Then Rest Of The File.Say In My File I Have "I AM HUMAN", It Prints "Error. HUMAN"!!

I Cant Figure Out Whats Wrong In The readFile() Function.It seems right to me.

View 4 Replies View Related

C++ :: Multiple Quiz Program - Adding High Score For Each User Stored In Binary File

Jul 11, 2014

I am making a multiple quiz program. So everything is working fine, except for the part where i'm trying to add a highscore for each user which is being stored in a binary file. I have added a sample of the program containing the error. This isn't the actual program, which is very long.

class user { //The collection of all info pertaining to the users
char user_id[50];
public:
int hscore1;
user() {
strcpy(user_id,"NULL");
hscore=0;

[Code] ....

View 1 Replies View Related

C++ :: How To Get Program Recognise User Input

Dec 8, 2013

I need the program to do a calculation after the user inputs 10 numbers . This is what I have tried so far:

int count;
float value, high,low, sum,average;
sum=0;
count=0;

input:
printf("Enter a number (enter negative value to finish program):
");
scanf_s("%f",&value);

[Code] ....

output:
average=sum/count;
if(count==10) {
printf("total values :%d
",count);
printf("The Highest value :%f
Lowest Value: %f
",high,low);
printf("The average of the values is:%f
",average);
}

View 3 Replies View Related

C++ :: Program That Accepts Two Input From User?

Dec 8, 2013

I built a program that accepts two input from the user, using a array inside a loop, it is pass to a function inside a class which will display the two number, the problem is when the user is inputting a number and it is 1 the program continuously as the user to input a number, and when 2 is entered the program ask another number and end, but for example you entered 2 and 3. . . it will then outpu 2 and 4 (so 3 + 1 ) and always the last number is plus one. here is the code.

main.cpp
#include <iostream>
#include "newclass.h"
using namespace std;

[Code].....

View 5 Replies View Related

C++ :: Program That Will Allow A User To Input Their First Name Into A String

Feb 23, 2015

So we have a weekend assignment that is "Write a c++ program that will allow a user to input their first name into a string, and use the switch/case statement to produce the following output. Your Program should prompt the use rwith the numbers and the options for each (school, classification, and mood) allowing them to make a choice"

My issue is with the output. The output at the end is the number that they input and not the name of the case they chose, so if they chose option 1 for school it does not print out "BRCC" at the end for the output it prints a 1.

#include <iostream>
#include <string>
using namespace std;
int main(void) {
string name;
cout << "Please enter your name: ";
cin >> name;

[code].....

View 7 Replies View Related







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