C++ :: Add And Subtract Two Sets Of Integer Arrays?

Apr 24, 2013

Ok so I am currently trying to add and subtract two sets of integer arrays. When I run my program, the program does not subtract the numbers from the first set with the numbers from the second set. Could anyone here take a look at my code and help me figure out what the problem is?

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

[Code].....

View 1 Replies


ADVERTISEMENT

C :: Add Two Big Integer Numbers Without Use Of Arrays

Dec 1, 2014

i'm having difficulty with a problem, i need to add two big numbers suchas 54646774456776 and another one 445556777554 and it would print the result. how can i approach this problem without the use of arrays?

View 4 Replies View Related

C++ :: Big Integer Class Using Dynamic Arrays

Mar 27, 2014

I have become overwhelmed an frustrated at these current operator overloads!

Currently I still can not get my +,* or istream operators working at all!

#include <iostream>
#include <cstring>
#include "myint.h"

[Code]....

View 1 Replies View Related

C++ :: Storing Integer Arrays Safely

Apr 22, 2013

I have an assignment where I have to design, implement, and test a class for storing integer arrays "safely". I do not know how to set up the destructor.

The goal of this programming assignment is to give students practice defining and using classes. In particular, students are required to design, implement, and test a class for storing integer arrays "safely". The array should be able to hold any number of integers up to 100.

In the class header file "SafeArray.h" students must define the class and specify the constructor/destructor functions, the public methods and private variables. In the class implementation file "SafeArray.cpp" students must implement the following operations:

constructor - to initialize the object.
copy constructor - to copy an object.
destructor - to delete the object.
set - allow the user to set a value of the array at a particular location.
get - allow the user to get a value of the array at a particular location.
print - print out the array.
add - add the elements of one array to another.
subtract - subtract the elements of one array from another.

The purpose of your main program "main.cpp" is to demonstrate that all of the methods above work properly. You should have at least one call to each of the methods, and print out the array as needed to show that the operations are performing correctly.

"SafeArray.h":

#ifndef SAFEARRAY_H
#defineSAFEARRAY_H
class Safe {
private:
// Declare variables to store A, B and C

[Code] ....

View 2 Replies View Related

C++ :: Adding And Subtracting Integer Arrays?

Apr 23, 2013

I am currently working on a program that uses a class to store integer arrays. I have most of the code done, but I am having trouble on the main.cpp part of my program. The program should display this:

OBJ 1:
2 3 4
OBJ 2:
1 4 -2
Addition:
OBJ 1 =
3 7 6
Subtraction:
OBJ 1 = 1 -1 6

But when I run and compile my program, this is what I get:

OBJ 1:
2 3 4
OBJ 2:

ADDING:
OBJ 1 =
4 6 8
Subtraction:
OBJ 1 =

Here is my current main.cpp:

Code:
#include <iostream>
#include "SafeArray.h"
using namespace std;

[Code].....

View 3 Replies View Related

C++ :: Class Defining And Storing Integer Arrays

Apr 23, 2013

I am currently stuck on what I should do next in a program I am working on. These are my instructions:

Design, implement, and test a class for storing integer arrays "safely". The array should be able to hold any number of integers up to 100.

In the class header file "SafeArray.h" students must define the class and specify the constructor/destructor functions, the public methods and private variables. In the class implementation file "SafeArray.cpp" students must implement the following operations:

constructor - to initialize the object.
copy constructor - to copy an object.
destructor - to delete the object.
set - allow the user to set a value of the array at a particular location.
get - allow the user to get a value of the array at a particular location.
print - print out the array.
add - add the elements of one array to another.
subtract - subtract the elements of one array from another.

The output of my program is suppose to look like this:

Set q1: 2, 3, 4
Print q1: 2, 3, 4

Set q2: 1, 4, -2
Print q2: 1, 4, -2

Add q2 to q1

Print q1: 3, 7, 2
Get q1 at 1: 7

Here is the code I have so far.

*main.cpp*

#include <iostream>
#include "SafeArray.h"
using namespace std;
int main() {

// Declare a SafeArray object
Safe obj;

[Code] ....

View 1 Replies View Related

C++ :: Passing / Returning Character And Integer Arrays With Functions

Jun 21, 2013

Passing and returning character and integer arrays with functions using simple programs...use pointers if necessary

View 1 Replies View Related

C :: How To Subtract Evenly

Feb 20, 2015

how do I subtract this so that I use the smallest number of $20, $10, $5, and $1 to pay $93? The book tells me to "Divide the amount by 20 to determine the number of $20 bills needed, and then reduce the amount by the total value of the $20 bills. Repeat this for the other bill sizes."I think the part in bold throws me off. What IS the total value of the $20 bills if I use $93 as the example? Is it $80, the highest we can go with $20 bills? Is it 4, the number I got from 93/20 after cutting off the decimal places, also the total number of $20 bills I can use?

I know how to do it and can do it in real life. It's like, "Oh, I need to pay $93. So I use four $20 bills, which brings me to $80. Using one more would bring it to $100, which is too much. So now, I need to use a $10 bill, which brings it to $90. Oh, so now, I need to use three $1 bills, which brings me to $93."But how do I tell that to a computer? It seems like I would have to put some kind of limits on it, or string code lines together,Here is the code so far:

Code:

#include <stdio.h>int main(void)
{
int amount, twenty, ten, five, one;
printf ("Enter a dollar amount:
");
scanf ("%d", &amount);
}

[code]....

View 5 Replies View Related

C :: Subtract 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. it not printing 5:30 minute subtract

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

[Code] ....

View 3 Replies View Related

C++ :: Subtract In A String With Decrementation

Nov 24, 2013

Here's my code :

>>>>>
std::vector<std::string> x = split("3 5", ' ');
int total = 0;
// then we loop over the elements
for(size_t i = 0; i < x.size(); ++i) {
// convert the string to an integer
int n = atoi(x[i].c_str());
total = total + n;
}
std::cout << "total = " << total << std::endl;
}
<<<<<

So, as you can see, this will add 3 to 5. However, I would like it to do the inverse (3 - 5). How I can do that?

View 2 Replies View Related

C++ :: How To Subtract A Set Value From Each Character In Array

Mar 16, 2013

this function subtracts a given value for each element in an array. I If the array is: hellohowareyou, and the value is 6 then result will be : 6 characters from each letter in the initial array

and the prototype of it is:

void minusFromArray(char arr[], int size, int value);

how do i convert each element in the array into ascii and subtract the values from those ascii characters?

View 1 Replies View Related

C/C++ :: How To Subtract Two String Containing Numbers

Mar 29, 2014

I have a code for subtract of two char arrays(size of each is 50).but i want to write this program with string and i should be consider that size of each string may be not equals.for example we have s1=4777 and s2=55.and we should be subtract them. This is my code.

char* sub(char x[50],char y[50]) {
int i,j,temp=0;
char z[50]={'0'};
for(i=0;i<50;i++)

[Code] .....

View 9 Replies View Related

C++ :: Function That Subtract Value From Each Character In Array

Mar 17, 2013

I have to write a function Subtracts val from each character in the array

// If the array is: abcdefghi and value = 5, then result is: 5 ascii characters subtracted from the given array
// note: Make sure the character remains in the ' '
// to '~' (inclusive)
// If character < ' ', then add 95
// If character > 126, then subtract 95
// to put back within the range, and repeat as needed
// all printable characters are between this range
// ' ' is the 1st printable character (32)
// '~' is the last printable character (126)
note: subtracting values from the char will cause an overflow.

the prototype is: void subtracting(char array[], int size, int value)

View 3 Replies View Related

C++ :: Compare Function On Sets

Oct 18, 2014

How can I declare a set of strings that i want to be ordered by a boolean function Comp? Like the one you would write in

sort(v.begin(), v.end(), comp);

I tried
set<string, Comp> S;
but it doesn't work

And the same question for priority queues, can you specify the function you want your elements to be sorted by?

View 4 Replies View Related

C++ :: Removing From A Vector Of Sets?

Apr 18, 2014

I have a vector of sets in which I wish to remove a set from the vector, if it contains a certain value, is there any way of doing this?

for(int j = 0; j <= clauseVector.size(); ++j){
if(clauseVector[j].find(find) != clauseVector[j].end())
std::cout << "FOUND: " << propagator << "
";
}
}

This is what I have been using to find the element, but is there a way to remove the set that contains the element?

If needed I can include the full code

View 11 Replies View Related

C :: Why Program Can't Subtract Negative Number From Positive One

Feb 2, 2015

My program uses a while loop to eventually get to an error of zero and a root of sqrt(3). I'm not understand why after the third iteration the program fails to compute a new x value. I'm using Visual Studio 2013. The code tag instructions were dubious.

Code:

#include <stdio.h>
#include <math.h>
main() {
/*This program uses the Newton-Raphson method to solve y = (x^3)-3 for it's roots.*/
printf("This program uses the Newton-Raphson method to solve y = (x^3)-3 for it's roots. Enter your estimate of the root.
");
float x,y,z;
int num;
num = 0;

[Code]...

View 1 Replies View Related

C :: Function That Scans In Two Sets Of Coordinates

Nov 5, 2013

Night now I'm working on part of a function that scans in two sets of coordinates. Is there a way I can scan both sets of coordinates in with the same scanf?

ex. scanf("%d%d%d%d," &destroyer_1, &destroyer_2, &destroyer_3, &destroyer_4)

but that didn't work...

Code:
printf("What are the first coordinates for destroyer:
");
scanf_s("%d%d", &destroyer_1, &destroyer_2);
gameboard[destroyer_1][destroyer_2] = 'd';
printf("What are the second coordinates for destroyer:

[Code] .....

View 5 Replies View Related

C++ :: Merging Sets In Linear Time

Jan 5, 2014

I have two std::sets S1 and S2 which I need to merge.

I know that the largest element of S1 is less than the smallest element of S2.

the additional information about S1 and S2 should enable me to do the insertion of each element in costant time instead of log(N).

what is the fastest way to calculate the union of the two sets?

View 6 Replies View Related

C++ :: Removing Part From A Vector Of Sets?

Apr 18, 2014

I have a vector of sets, which I am removing any element which contains a certain value. For example, if I was looking for 2:

[0] 1 2 3
[1] 4 5 6

After the program was run, I would be left with just [0]4 5 6.

This is the code I have been using

auto iter = std::remove_if( clauseVector.begin(), clauseVector.end(),[propagator] ( const std::set<int>& i ){
return i.find(propagator) != i.end() ; } ) ;
clauseVector.erase( iter, clauseVector.end() ) ;

I want to know, is there any way I can tweak this code so that it only removes one part of the set rather than the whole thing. For example with above example, I would be left with

[0] 1 3
[1] 4 5 6

View 4 Replies View Related

C++ :: Parsing Through Large Data Sets

May 30, 2013

So I'm attempting to write a program that will parse through a large file (genome sequences) and I'm basically wondering what options I should consider if I wanted to either:

a) store the entire genome in memory and then parse through it
b) parse through a file in small portions

If I go with "a", should I just read a file into a vector and then parse through it? And if I go with "b" would I just use an input/output stream?

View 5 Replies View Related

C++ :: Running Certain Code In Codeblocks Sets Off AVG?

Jul 3, 2012

I've recently started to learn C++ and I'm using codeblocks as my IDE, but I keep getting problems with AVG free edition picking up random pieces of code as Trojans ?! I've put an example of some code that sets it off below, and the error message I get. Is there anyway I can set AVG not to trigger with any codeblocks coding I've done? I guess I could tell AVG not to trigger for that folder, if that's even possible?

Code:

#include <iostream>
using namespace std;
class MyClass{
public:
void coolSaying(){
cout << "BUST A MOVE!!" << endl;

[Code] ....

Error I get:

File name: h:DesktopC++ projectsclasses and objects 1 inDebugclasses and projects 1.exe
Threat name: Trojan horse Agent3.BMSZ
Detected on open.

View 14 Replies View Related

C++ :: Find Intersection / Union And Difference Of Two Sets

Feb 17, 2014

The program is to find intersection,union and difference of two sets. The program take the input correctly but after it crashes with the message that some exe is not working...

Code:
#include<iostream>
using namespace std;
void Input(int *A, int*B, int size1, int size2)
//input function {

[Code] ....

View 3 Replies View Related

C++ :: Maximum Numbers Of Elements That Can Be Eliminated From A Set Of Sets?

Nov 17, 2014

I have come across a problem lately. You are given a set of n sets with m variables.. for instance {a,b,c,d}, {b,c,d}, {b,c}, {c,e,f}, {e,f}. And you want to eliminate elements from these sets with the restriction that you can only eliminate one item from each set and each item can only be eliminated from one set (i.e. if you've eliminated b from set {a,b,c,d}, then you cannot eliminate it from {b,c,d}). The problem is writing an algorithm which determines the maximum number of elements you can eliminate. And I'm hopelessly stuck... of course, you could backtrack it and determine this number but I feel it could be done more efficiently..

View 2 Replies View Related

C++ :: Program That Add / Subtract / Multiply Or Divide Two Integers - Incorrect Answers

Oct 7, 2012

Create a program that adds, subtracts, multiplies, or divides two integers. The program will need to get a letter (A for addition, S for subtractions, M for multiplication, or D for division) and two integers from the user. If the user enters an invalid letter, the program should display an appropriate error message before the program ends. If the letter is A (or a), the program should calculate and display the sum of both integers. If the letter is S (or s), the program should display the difference between both integers. When calculating the difference, always subtract the smaller number from the larger one. If the letter is M (or m), the program should display the product of both integers. If the letter is D (or d), the program should divide both integers, always dividing the larger number by the smaller one."

And here is the test data. I am posting the results from my desk-check table.

operation first integer second integer answer
A 10 20 30
a 45 15 60
S 65 50 15
s 7 13 6
G -1
M 10 20 200
d 45 15 3
d 50 100 2

Then, I transferred my program into a source file. Here it is:

//Exercise16.cpp - display answer of two integers

#include <iostream>
using namespace std;
int main() {
//declare variables
int firstInteger = 0;

[Code] ....

After putting in the data, everything worked fine, except the last two operations, which are M (multiplication) and D (division). All the answers for the last two operations essentially give me a 0.

View 4 Replies View Related

C++ :: Function That Computes Result Of Formula For Two Sets Of Inputs

Nov 14, 2013

I'm currently writing a program and a portion of it needs to have a function that computes the result of a formula for two sets of inputs. It then has to calculate and display the difference between the two results.

I have code that takes the input from the user and converts it to the type that I need. In this case we are talking about latitudes and longitudes that will be converted to degrees, then to xyz coordinates.

View 1 Replies View Related

C++ :: Calculator That Takes Two Large Numbers In Linked List Then Ask User To Add Or Subtract

Dec 30, 2012

What I'm trying to do is make a calculator that takes two large numbers in a linked list then ask the user if they wish to add them or subtract them.

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

class Node {
public:
int value;
Node * next;

[Code] ....

View 5 Replies View Related







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