C++ :: Eliminating Jumping Repetitions Of Different Orders
Feb 26, 2014
I wrote a program for class. It did its job, but I want to make it better. The program finds all of the Pythagorean triples between 1 and 100.
As you can see, the program will repeat the same Pythagorean triples but in different orders.
What I want to do is have the program repeat each Pythagorean triple once, regardless of whether the ordering is different. I have tried, but only came up with the solution to solving repetition that is consecutive. But the repetition for Pythagorean triples jump around.
I got stuck on how to eliminate jumping repetitions. I only know how to make it not repeat on consecutive entries.
View 5 Replies
ADVERTISEMENT
Feb 25, 2014
I wrote a program that finds the Pythagorean triples for class. It did its job, but I want to make it better. The program below finds all of the Pythagorean triples between 1 and 100.
As you can see, the program will repeat the same Pythagorean triples but in different orders.
What I want to do is have the program repeat each Pythagorean triple once, regardless of whether the ordering is different. I have tried, but only came up with the solution to solving repetition that is consecutive. But the repetition for Pythagorean triples jump around.
E.g., Pythagorean triple (6, 8, 10) appears. Then two Pythagorean triples later, (8, 6, 10) appears.
I got stuck on how to eliminate jumping repetitions. I only know how to make it not repeat on consecutive entries.
I nested one for loop, in another for loop that is nested in another for loop. One for loop for each of the values in the triple. The most nested loop is for the c value in a^2 + b^2 = c^2, and has an if statement: if( ((a*a)+(b*) == (c*c) ) , and then the program prints the numbers.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
unsigned int a, b, c;
char con;
cout << "This program finds the pythagorean triples between 1 and 200.
[code].....
View 5 Replies
View Related
Feb 22, 2015
I am trying to include all repetitions for just one turn but I keep getting
00.0 but I want (the one in red)
170.3 0 0.3
180.0 17 0.0
190.3 18 0.0
200.3 19 0.3
210.0 20 0.3
220.0 21 0.0
22 0.0
so basically I call a function that represents just one turn of getting a random number, and then when the player decides he wants to get a random number that is at least 17 and wants to repeat this 3x I have to print out this chart that shows the chances of the player rolling the numbers between 17-22 [how many times does he get 0,17,18,19,20,21,22] this is what I have
cout << "your score: " << (' ') << "chances for that score:" << endl;
/* score is the player's total score for the one turn */
int score = 0;
int score0 = 0; // 0
[Code]....
View 3 Replies
View Related
Jan 1, 2015
Why my pointer skips over the colour addresses, it jumps to the next size address when I use Pointer++. I have tried changing the the char array to 4 bytes instead of 32 and whatnot but it doesn't work.
If I set the Pointer = the first colour address, it skips over the size addresses and only get the colour addresses. I know using 2 arrays would easily solve everything, but sadly I must use only 1.
I'll post whatever relevant code here:
View 3 Replies
View Related
Nov 9, 2013
So, as the title says, I'm trying to eliminate false sharing, or, eliminate sharing writes between threads with TBB. The question is how.
Normally I'd make an array whose size is equal to the number of threads, then locally write to a local variable and update the array only at the end of the thread.
But, of course, I cannot seem to get either thread id or total number of threads TBB uses. I found a reference to tbb::enumerable_thread_specific, which as I understand, is supposed to work for exactly this. But as soon as I added it, it hurt performance by ~60% instead of making it better.
How to do this properly? You don't really need to look so hard on how the algorithm works (I don't know either). I know it's not quite right right now due to race conditions, but I'll fix that later. I used a reference implementation that I copied™, and my task is to parallelize it.
The parts where the problem is right now is in red (of course, it's not all problems; it's only a subset of them).
Code:
#include <iostream>
#include <vector>
#include <fstream>
#include <ctime>
#include <algorithm>
[Code] ....
View 11 Replies
View Related
May 11, 2013
I am trying this program for eliminating the vowels from a text.
#include <iostream>
#include <vector>
#include <ctype.h>
bool isVowel(char c, int indx) {
c = tolower(c);
if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'))
[Code] ....
Here is an error while debugging that while trying to match the argument list '(std::istream, std::string).
View 7 Replies
View Related
Apr 6, 2014
This program works as expected:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
unsigned long long int address;
float current;
unsigned char pressure_units;
}
[code]....
But I don't like how I had to use malloc and free. Is there a different way to accomplish copying the string into a char pointer without resorting to dynamic memory allocation?
View 1 Replies
View Related
Jan 30, 2015
We've only covered up to Functions and how to use reference variables inside the function parameter.
One of the hw problem that was assigned was to write a void function that takes three parameters( num1, num2, num3) by reference and sorts their values into ascending order, so that num1 has the lowest, num2 the middle value, and num3 the highest value. For example, if user enters: 14, -4, 8, then the output should look like this:
-4
8
14
I've completed the program with a bunch of if/ else if statements but I was wondering if there was a more efficient way to sort the numbers. Bear in mind, we've only covered materials up to functions so I can't use any other new techniques that we haven't cover yet. Here is my code:
// This program will take three int parameters by reference and sorts their value into ascending order
//so that num1 has the lowest value, num2 has the middle value, and num3 has the highest value
#include <iostream>
using namespace std;
// declare function with reference parameter that with sort numbers
void sortNum(int &, int &, int &);
int main ()
{
[Code]....
View 2 Replies
View Related
Jul 29, 2014
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main() {
const int arraySize=20;
[Code] ....
View 5 Replies
View Related
Feb 26, 2015
The tools Hal's sells are: Hammers: $10.99 Wrenches: $10.99 Levels: $19.99 Tape Measures: $4.99 Screwdrivers: $8.99
In order to make things easier in the long run you have decided to make a c++ program that takes in all the orders for each register and tallies them at the end of the day.
Write a c++ program that does the following:
Create a Register class that can store all of the receipts for the day and the totals for that register.
This class could have the following member functions:
Contructor(int) - Creates a number of receipts based on an integer that is passed into the constructor (this is the largest number of orders that the register can take). You may also be required to create additional variables to make the program work but that's up to you to determine.
void getorder() - Asks the user how many of each item they want an stores that in the first available receipt.
void returnreceipts() - This function returns the details of all the receipts and the total for the day.
Register operator+(const Register &right)- This is an overloaded addition operator. When two objects are added together an empty temporary register is created (with 0 receipts) and only the totals of both objects are added to it. The temporary register is returned by the function.
Register operator=(const Register &right)- This overloaded assignment operator copies only the totals from the Object on the right.
In the Main function I would like:
Create 3 Register Objects. The first two registers are the ones in the store and should be initialized to take 10 orders. The third is used at closing time and can be initialized with 0 receipts as it will only take in the totals from the other registers.
Run the getorder function for registers 1 and 2 twice.
Run returnreceipts for register 1 and register2.
Reg3=Reg1+Reg2;
Run returnreceipts for register 3.
[Code]...
this is what I have so far I'm trying to get the input part working first, so the user would be asked each item individual how many they want? this will happen for 2 users, then the next register will do the same?
View 2 Replies
View Related
Apr 18, 2014
[URL]
According to my project instructions, I have to make a "validation on the delete button, that before a record can be deleted it will check to see if the count of "In-Progress" orders for that product is 0. If it is greater than zero, it should not allow this record to be deleted."
So far I have on the code behind page:
protected void btnDeleteProduct_Click(object sender, EventArgs e)
{
DataView dv = (DataView)SqlOrders.Select(DataSourceSelectArguments.Empty);
[Coe].....
The professor said I have to: "As for getting the count, check your notes and book, specifically looking at SQL and the Aggregate functions. There is a function we talked about in class called "Count(OrderID)" and set the where clause to check for the productID.
View 2 Replies
View Related