C++ :: Creating Binary Calculator - Output Operation Of Subtraction

Feb 10, 2014

I need to create a binary calculator that outputs the operation of subtraction whenever you input 2 4 bit binary numbers. For example:

If I enter

1000
- 0111

View 1 Replies


ADVERTISEMENT

C :: Addition And Subtraction Calculator That Takes Input?

Feb 23, 2013

I'm writing an addition and subtraction calculator that takes input as: 5+6-3+2. You should be able to add or sub as many numbers as you want. I want the while loop to stop when the user hits enter. I put the getchar() function to catch the and break the loop but it is also swallowing the '-' sign, which I want to use to subtract and is instead adding the numbers with "sum+=number". How can I get around that?

Code:

#include <stdio.h>
int main(int argc, char *argv[]){
int number, sum = 0;

[Code]....

View 3 Replies View Related

C++ :: Calculator Using Stack - How To Convert Operation From Infix To Postfix

Sep 25, 2013

I trying to write a code for a calculator using stack is how to convert an operation from infix to postfix . Here is my attempt I created a header file.

#ifndef STACK_H
#define STACK_H
#include <iostream>
using namespace std;
template<class T>
struct node {
T item;

[Code] .....

View 1 Replies View Related

C++ :: Creating Exact Age Calculator?

Aug 3, 2014

I've been wondering this, since there is so many things which needs to be taken care of. I created one, but it wasn't precise.

View 19 Replies View Related

C/C++ :: How To Solve Illegal Structure Operation Error In Binary Operator Overloading

Aug 1, 2013

#include<iostream.h>
#include<conio.h>
class sum {
    int a,b,ans;
public:
void  geta() {
  cin>>a;

[Code] ....

View 1 Replies View Related

C :: Creating Simple Calculator By Splitting The Program In 3 Files

Feb 21, 2014

I am new to C programming, I have been given an assignment to create a simple calculator by splitting the program in 3 files. It should have 2 .c files and 1 .h... I went through the internet extensively and could only come up with this.

main.c:

Code:

//Calculator main.c
#include <stdio.h>
#include <conio.h>
#include "Functions.h"
int main() {
float x = 0, y = 0;
int operation;

[Code]...

Functions.c

Code:

#include "Functions.h"
extern float x, y;
float addition (float a, float b) {
return a + b;

[Code]...

Functions.h

Code:

#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED
float Sum(float a, float b);
float difference (float a, float b);
float remainder (float a, float b);
float product (float a, float b);
#endif

When I do a 'cl main.c' on the Developer Command window for VS2013, i get an error that reads :

main.obj
main.obj : error LNK2019: unresolved external symbol _difference referenced in function _main
main.obj : error LNK2019: unresolved external symbol _product referenced in function _main
main.obj : error LNK2019: unresolved external symbol _addition referenced in function _main
main.exe : fatal error LNK1120: 3 unresolved externals

View 5 Replies View Related

C# :: Creating Complex Number Calculator - Convert String To Ints

Sep 18, 2012

I am working on an assignment to create a Complex number calculator. In this assignment I am to ask the user for input to the calculator. We are given a sample run output that looks like this.

Enter operand1: 3 4
operand1: (3, 4)
Enter operation : +
Enter operand2: 1 2
(3, 4) + (1, 2) = (4, 6)

My question is how would I take from the user: an integer followed by a space followed by another integer and convert that into two seperate accessible int values that I can save as real and imaginary values.

View 4 Replies View Related

C++ :: Grade Calculator - Output With Comment To A Text File

Feb 24, 2013

I am a math teacher who is taking a programming class. My district wants to incorporate some programming tasks into the high school math curricula. I am working on a project to calculate a final grade and output this along with a comment to a text file. The following data is the input that I created:

3 300 100 100 100 .15
4 400 100 98 94 92 .45
3 300 98 100 92 .40

The final grade output results in gibberish.

#include <iostream>
#include <fstream> // For file I/O
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

[Code] ....

View 6 Replies View Related

C++ :: Creating Variable Name For Binary File

Dec 11, 2013

I'm attempting to split a large binary file into smaller manageable files for analysis. I've written most of the software but I'm stuck in a couple of places.

1. The binary file is split by looking at a couple of bytes to determine when to create a new file or continue appending to the current new file. The question is when I need to create a new file, how can I dynamically sign it a name? My intention is to rename each subfile by: "original_name" + new section id + ".log".

2. The start of each section is determined by a specific pattern (6 bytes of FF's). I'm running into an issue where the pattern check is checking for 5 bytes instead of 6 because the for..loop doesn't increment for one instance.

I've attached the code I have so far.

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;

int append_to_file(FILE *f,long sec_start, long sec_end)

[Code] ...

View 2 Replies View Related

C/C++ :: Creating A Binary Search Loop?

Oct 13, 2014

I am creating a binary search program that lets the user input up to 10 integers and then the program displays the array and sorts it. When the user is prompted to select an integer, if the integer is in the array, the program responds with the array subscript part. I can get the loop to work once and maximum twice, but then it wont search for the array or say value not found even though the number in in the array. I tried making the values NULL but that only lets me go through it one more time.

Here is my code:

#include <iostream>
using namespace std;
//Functions
void printArray(int);
void selection(int);
int binarySearch(int,int,int);

[code]....

View 6 Replies View Related

C++ :: Creating Non-text Readable Binary Files

Jun 23, 2014

I'm currently trying to create binary file will not be able to be read as texts and will contain metadata(more like image files).

But I've tried writing to .dat, .bin files in binary mode and all of them are displaying in ascii text..which I don't want.

View 3 Replies View Related

C++ :: File Input And Output - Creating Graph Plotting Points

Feb 10, 2014

So I am trying to create a program that reads a series of files and creates a graph plotting points from the file. So far my code looks a little something like this -

include <iostream>
include "ccc_x11.h"
include "ccc_shap.h"
include "ccc_win.h"
include <fstream>
using namespace std ;
int ccc_win_main() {
cwin.coord(-10, -10, 10, 10);

[Code] ....

However when I run the program nothing happens. I think it has to do with the way I set up my files, which looks a little something like this-

-9 -9 -9 -9 -9 -9 -7 -7 -6 -6 -5 -5 -4 6 3 1 -1 -3 -6 5 -5 4 -4 2 -2 0

The first thirteen numbers are the x values of the points, and the last thirteen are the y values of the points. Is there any other way to have my program read the file and display the given points?? I would use getline() however that would make my point into a string, and I dont really know how to convert a string to a double before putting the variable into a point.

View 2 Replies View Related

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 View Related

C++ :: How To Output All Possible Binary Combinations

Mar 4, 2014

I need to create a function that outputs all possible binary combinations. I'm really stumped on this. I have to do it with nested loops, and am not sure how to go about it. Below is what I tried so far.

The output should look like this:

00000000
00000001
00000010
00000011
00000100
...
11111110
11111111

Code:

void outputBinary(){
int a[2][2][2][2][2][2][2][2];
for (int i = 0; i < 2; i++){
for (int j = 0; j < 2; j++){

[Code] .....

View 2 Replies View Related

C/C++ :: 3 Led Output Binary Counter

Oct 4, 2014

I need to get up to speed in Embedded systems. I need to create a 3led binary counter, when an input is operated the it needs to count up using these leds from 0 to 7. I have written this so far and how to pulse a counter or interger to 7 and then reset back to 0.

int main (void) {
LED_Init_1();
LED_Init_2();
LED_Init_3();

[Code]......

View 2 Replies View Related

C :: Positive Binary Output Function

Mar 27, 2013

I have written a function that takes in a positive decimal and returns its Binary equivalent; however, the output always adds an additional zero to the binary. What could I do to get rid of it?

If the number is 7, it outputs 0111 instead of 111.

Code:
#include <stdio.h>
void Dec(int n) {
if(n > 0)
Dec(n/2);
printf("%i", n%2);

[Code] ....

View 2 Replies View Related

C++ :: Output Address Of Variable In Binary?

Sep 24, 2014

How can I output the address of a variable in binary?

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

[Code] ....

View 2 Replies View Related

C :: Simple Decimal Input To Binary Output

Jun 22, 2013

I am learning c because I want to get back into programming microcontrollers, which I previously did in assembly. I wanted to make something fairly tight in terms of program memory and RAM to show me an output in binary form. When you are troubleshooting a file register or serial interface when you can see the actual bit values (on a small LCD for a micro-controller) and compare it to a datasheet.

Code:
#include <stdio.h>
#include <math.h>
int main() {
int i;
int decimaltoconvert;
int convertingarray[7];
int convertingarray2[7];

[Code] .....

Also, how might I go about putting that into a function that I could call?

View 6 Replies View Related

C++ :: Subtraction Of Two Integers?

Apr 18, 2014

I am working on an assignment where I have to subtract two very large integers. How can I write it's code provided that I have both numbers in a character array with each index holding a fraction of the original number. Like if I have a number 123456789 in an array then

arr[0]='1';
arr[1]='2';
arr[2]='3';
arr[3]='4';
and so on. n

nNw if i have to subtract this number from an other number, how can I do that?

View 4 Replies View Related

C++ :: Separate Binary String Every 4 Characters - How To Add Spaces To Output

Sep 28, 2014

I want to separate this binary string every 4 characters..I am trying to get a better understanding of how variables are stored in memory and I am looking at their binary address for a pattern..I see a pattern for the last 4 bits

#include <iostream>
#include <bitset>
int main() {
using namespace std;
int x[100];

[Code] ....

View 2 Replies View Related

C/C++ :: Incorrect Output From Unsigned Binary To Decimal Program

Feb 2, 2015

This program has to convert an unsigned binary number into a decimal number. No matter what binary number I enter, however, it always outputs that the decimal number is 0.

My code is as follows:

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
string binarynumber;
cout << "Enter an unsigned binary number up to 32 bits." << endl;

[Code] ....

And my output:

Enter an unsigned binary number up to 32 bits.
00001111
That number in decimal is 0

The output should have shown the binary number in decimal to be 15, and I cannot find my error.

View 6 Replies View Related

C/C++ :: Subtraction - Two Time Intervals

Mar 12, 2014

I am looking for simple code that subtract two time interval. I have time t1=5hour 30 minute and other time in 24 hour format. This code i written but it not working as expected

main() {
intTime1;
intTime2;
int hour=10;
int minute=5;
int second=13;
int h;int m;

[Code] ....

Is there any easy way of doing above code. Above two code section not working....

View 8 Replies View Related

C++ :: Accept Signed Decimal Integer As Input And Output In Binary

Jan 29, 2015

Write a C++ application program to accept a signed decimal integer as input and output the equivalent 2s complement version in 16-bit binary. Include a space between every four bits in the output string. The input will only be processed by the application if it falls in the valid range that can be represented in 2s complement format with 16 bits. The range of a decimal number from - to + is -32768 to 32767.

View 3 Replies View Related

C/C++ :: Matrix Class - Addition / Subtraction

Jul 7, 2014

I'm working on a matrix class and I've hit a few snags. Here's what I've got so far:

Matrix.h

#include <iostream>
#include <conio.h>
using namespace std;
class Matrix {
private:
int matrix[50][50];

[Code] ....

Where I have questions is in implementing the addition and subtraction bits into the class itself. I understand that I'm going to have to do a copy operation (this from reading in C++ Primer Plus 5th Edition). Right now I'm just after adding/subtracting as the rest will be variations on the same theme.

So, here it goes:

As I understand the problem, I need to pass my two matrices as arguments to an addition function. This is going to involve having to copy the values of the two existing matrices into temporary matrices within the addition function, then I'll add them, and store them in a new matrix which will be my return value. So...something like this:

int Matrix::matrixAdd(int R, int C, const Matrix & matrix1, const Matrix & matrix2) {
int sum;
Matrix matrix;
for (int i = 0; i < R; i++)

[Code] ....

I do end up with errors there...C2240, and C2662. Again, I'm new to working through this, but that's what I've got. My idea is that I'm passing the maximum size of the array as defined by the user, in this case a 2x2 array, it'll cycle through and add up to that imposed limit...I went 2x2 because it's small enough that testing doesn't drive me up a wall.

View 14 Replies View Related

C++ :: Variable Length Integer Subtraction

Aug 24, 2013

On a controlled buffer of unsigned char it is possible to do subtraction faster than if you followed standard mathematical rules, here is an example:

typedef unsigned char uchr;
uchr num1 = 5; //00000101
uchr num2 = 3; //00000011
num2 = ~num2; // 11111100
++num2; // 11111101
uchr num3 = num1 + num2; // 00000010(2) - computer truncates result to fit char

Since you will be working with a buffer you don't even need to worry about truncating the final bit because the add function will not be able to reach it - unless it is given the ability to grow the buffer in which case you just set the bit to 0 yourself

View 8 Replies View Related

C++ :: Output Compiled Script Into Binary File - Scripting Tool Algorithms

Dec 25, 2014

I am working on a script compiler that must output compiled script into binary file. Compiling etc is not a problem. The problem is detecting some specific cases. Nothing seems to work. If it works, then it breaks as soon as i modify the script.

Here is example "script1":

Code:
1VAR1 c1 = 44
2VAR2 c2 = 66
3beginscript
4if(c1=44)
5do_nothing

[Code] ....

Second example "script2", when there can be also some command between ENDIF and ENDIF. In this case: do_nothing command.

Code:
1VAR1 c1 = 44
2VAR2 c2 = 66
3beginscript
4if(c1=44)
5do_nothing

[Code] ....

The INDEXES before each line are not in actual script. They are just to point YOU to specific lines. Although the INDEXes are in compiled script!! This is very important. As you see there can be simple IF_ENDIF and nested (more complex) IF_ENDIF.

i.e IF_ENDIF inside another IF_ENDIF.

There are also IF_ELSE_ENDIF and some other ones, but im trying to make simple IF_ENDIF work first.

ENDIF is "SPECIAL" command, the IF, DO_NOTHING are "usual" commands.

"Usual" commands must always jump over(!) the ENDIF. ALWAYS!!

They must "ignore" them!

One strong RULE is like this for usual commands: always jump over any ENDIF, not matter what. If there is one, two or more ENDIF's in a row, then just jump over them to the closest NEXT usual block command. If there is some "usual" block command between multiple ENDIFs, then jump to this command and this command must therefore check whats next command right after it. And do the same: check if next command is ENDIF, if yes, jump over it, until "usual" block command is found.

This is the place im stuck. When i some time ago thinked about some ideas, i saw some patterns. One of them was that: Seems like if its nested IF_ENDIF, then every usual block command jumps out of it, i.e. right after the final ENDIF of this current nested IF_ENDIF.

But as soon as i added do_nothing between the two ENDIFs the so called "pattern" broke. In script2 above you see index 11 is do_nothing. Ok its in nested IF_ENDIF it should jump out to command index 17. But no, because there is do_nothing between index 13 and 16. If we jump out at index 11, the command 14 would never execute. This is a BIG NO. One idea i was thinking and trying was to use STL::FIND, STL::FIND_IF to find next "usual" command after specific index. But my code seems to crash sometimes and not work always.

Code:
bool NextNonENDIF(int i) {
return (i!=98);
}
int findNextBlockCmd(vector<int>&vec, int curidx)

[Code] ....

Here i pass him the vector that contains all the command TYPES in current script. Each command has its own TYPE or better called unique ID in which way compiler knows what is what. So in this case im trying to find a command thats NOT "ENDIF", in other words im trying to find next usual command after specific type of command. Lets just say the TYPE or unique ID of do_nothing is 555, im trying to find it.

How i should continue with this? What to use maybe stl::stack, some custom command indexing, some sort of labelling for usual commands in nested IF_ENDIFs or what?

In general, look script2, and i ask: There is index 11, this guy should look if there is any usual block command left for him before the final ENDIF at index 16. If there is, jump to it. If there is none, jump out of this nested IF_ENDIF to index 17.

Question: how to do it? What algorithms to use? I can use STL, BOOST, whatever. And i can use C++11.

View 1 Replies View Related







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