C++ :: Print All Combinations Data
Nov 27, 2013
I wanted to create a 5, 3 combinations. i know how to calculate to get the number of combinations 5 3 would have (which is ten), but it seem it's a bit harder for me to print those data ...
View 2 Replies
ADVERTISEMENT
Mar 6, 2015
Coding for- To print all combinations of numbers that can compose a given number..
View 3 Replies
View Related
Mar 28, 2015
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int r = 0;
int c = 0;
int num[17][15] = { 0 };
[Code] ...
// Here is my code for displaying the data from the text file into a 2d array and height next to it, but I am not able to diaplay the height from 60 to 76 next to the row of the 2d array, as shown in the table below. This is my program:
Recently the health authorities have listed a new way to calculate the body mass index (BMI) of an individual.
Values of 20 – 24 are classified as normal, 25-29 as overweight, and 30-34 as heavy.
The table below is a portion of a typical BMI table.
BMI:202122232425262728293031323334
Height:
60102108113118123128133138143149154159164169174
61106111116122127132138143148153159164169175180
.
.
.
MY task is to write a program that does the following things:
1.Produce the table by reading in the data from bmi.txt (on Moodle) into a 2-D array.
2. Display the table neatly on the screen, with row and column headings. The BMI should go from 20 to 34. The height should go from 60 to 76 inches.
3. Prompt the use for their height (in inches) and their weight.
4. Make the program print the closest BMI.
If their weight is lower than the values on the table, use 20 as the BMI.
If their weight is higher than the values on the table, use 34 as the BMI.
5.Loop the program so the user can find more BMI’s.
View 7 Replies
View Related
Mar 7, 2013
A few days ago I got a "bright idea" to see if I could match a string, with an arbitrary length from 1 to 12, to its formulated sequence by using an algorithm to find all possible combinations of the integer combinations from 0 to 9 at each length (1 to 12).
Example: Desired numerical combinations from integers 1 to 3:
At Length 1:
1, 2, 3
At Length 2:
11, 12, 13, 21, 22, 23, 31, 32, 33
At Length 3:
111, 112, 113, 121, 122, 123, 131, 132, 133, 211, 212, 213, 221, 222, 223, 231, 232, 233, 311, 312, 313, 321, 322, 323, 331, 332, 333
And so on until the nth length (in my case a length of 12).
First off, I would like to say that this is not as easy as I thought. I clearly underestimated the problem seeing as I've spent hours attempting to write a working algorithm, but feel like I've made no progress.
Here are a few of my attempts:
Attempt 1:
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
[Code]....
I can't exactly explain this one. It works if the length is 2 or less; however, the order of the output is horrendous.
Attempt 3: I tried using recursion, but only found myself getting more and more lost the further I tried developing my function. Cannot find my work for this attempt.
I would really like to figure this out on my own, but I am very stuck as you can see. I also lack time that I can spend working on this since im a full time student.
View 14 Replies
View Related
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
Feb 26, 2015
How to find all possible combinations of coordinates on a 2d grid with a given sum. The sum is not fixed!
E.g. N=nxm=25 thats our grid.
The sum=distance between points on a grid.
For two points distance=|(x1-x2)+(y1-y2)| point A(X1,Y1) B(X1,Y1)
My interest is to know how to find the combinations of coordinates with a given sum, it doesn't matter how many points are there.
If i enter the sum e.g sum=7 and the program has to show all possible combinations which gives the sum of 7 the number of point does not play in row they might be two or maybe more.
View 4 Replies
View Related
Jan 25, 2013
Code:
#include<stdio.h>
#include<string.h>
#define a 15
[Code]....
I am trying to print all combinations of a string but I couldn't figure out how to do loop for it. Code works only 2-3-4 letters words
View 4 Replies
View Related
Feb 17, 2013
I am trying to write a program for printing all the combinations of a string. Why this program is giving the error message.
"First-chance exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4..
Unhandled exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4.." when i try to run this in MVS 2010
#include<iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<conio.h>
void combination(std::string input,int length,std::string buffer,int allowedno)
[Code] .....
View 1 Replies
View Related
Jun 23, 2014
How to get all the possible combinations for 4 digits from a 5 digit number. I need a pair that has both 5 digits and four digits. their sum must be equal to a five digit user input. i.e.
user input : 14690
output:
14690 has pairs 12345 + 2345
2345 came from 12345
lets say that x = 12345 and y =2345
besides y == x%10000
other formula can i have since if i use % and / i will have a lot of declarations....
View 2 Replies
View Related
Feb 14, 2013
I have an integer vector of size "n".
e.g.
std::vector<int> vec;
vec.pushback(0);
vec.pushback(1);
vec.pushback(2);
vec.pushback(3);
Now I want to generate all possible combinations of size = {0, 1, 2, ... , n}.
{0, 1, 3} is not equal to {3, 1, 0} or {1, 0, 3} or {3, 0, 1}
View 7 Replies
View Related
Jan 12, 2015
how to write a password cracking program that will try all possible char combinations for just two chars (without duplicating any combination guesses). Obviously, there would only be 4 possible truth table combinations for two boolean values, but how would a person calculate the number of all possible combinations for two values with 70 different possible chars?
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
/*
Boolean Truth Table for two values:
p q
-----
T T
T F
F T
F F
Note that there are 70 chars in all specified above.
It will require much more than a simple truth table to try every possible char combination (especially if the password to be cracked is 2 or more chars). Using this guy's code: [URL] ..... as a starting point, I'm writing a program that will crack a password with a length of just 2 chars.
*/
int stringLength = 2;
char genRandom() {
return alphanum[rand() % stringLength];
}
int main() {
std::string password = "Sp";
srand(time(0));
std::string Str;
[code]....
View 19 Replies
View Related
May 7, 2014
I created a basic socket server, which listensing for incoming udp data. When I run the netcat program, I get a response:
Code:
$ nc -luv 1732
Connection from 10.50.11.12 port 1732 [udp/*] accepted
(?@??8?? ??.?n?5
(?@??8?? ??.?n?5|?>)
(?@??8?? ??.?n?5|?>)
^C |?>)
But with my c program it doesn't give the response. It should say something like "here is the message: " and then give a message.
Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
[Code] .....
View 2 Replies
View Related
Oct 22, 2014
I was recently introduced to the fstream header file. I want to know is their a easy way to print an output with append data in a .txt file.
And secondly I am also having an error with my header file. It says error: cannot open source file "fstring" when I hover my mouse over "#Include<fstring>".
View 7 Replies
View Related
Apr 4, 2013
I have a gridview in which I show report data, I wanted to print this data, so I added print functionality. This print functionality does not print entire gridview data, it only prints data which is visible on the screen and skip the data which is under vertical scroll bar.
Below is the print grid view code in c# for WINDOWS APPLICATION.
private void btnPrint_Click(object sender, EventArgs e)
{
if (printDialog1.ShowDialog() == DialogResult.OK)
{
[Code]....
View 3 Replies
View Related
Sep 15, 2012
Printing out a sequence data structure. I am using a PC running Windows 7 with Microsoft Visual Studio 2008. This sequence has a dynamic array which stores a value_type which can be any of the built in data types for C++. Initially the sequence is 30 slots long. When the program starts the user starts at the beginning of the sequence by choosing the "!" option from the menu. The user will then insert a number such as 11 by selecting the "I" option (upper or lower case). Then the user will go to the next position in the sequence by selecting the "+" option then insert 22, then go to the next position and insert 33.
To show that the numbers are actually in the sequence the user goes back to the beginning of the array by selecting "!" and then select "C" to display the current number of 11. Then the user goes to the next position by selecting "+" and then "C" to display 22 and so forth. At this point the member function called current() works just find , but when trying to print the contents of the entire sequence the program displays garbage. Why?
Code:
// FILE: sequence_test.cpp
// An interactive test program for the new sequence class
#include <cctype> // Provides toupper
#include <iostream> // Provides cout and cin
#include <cstdlib> // Provides EXIT_SUCCESS
#include "sequence2.h" // With value_type defined as double
using namespace std;
using namespace CISP430_A2;
[Code].....
View 2 Replies
View Related
Apr 4, 2014
The first line of my input file is going to contain some number "T" which will represent the "combination length" of a list of random words. (In this case, they are Taco Bell items). The first number on the second line represents the number of unique items on the menu to get, and the second number on the second line represents the number of unique items that are supposed to be bought.
Basically the input will look like this: 2 3 2 taco burrito nacho
And the output looks like this: burritos nachos nacho taco burrito taco
This is what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
int main(void){
int N, T, K;
char menu[N][20];
[Code] .....
What I am trying to get working right now is just to scan a file and put the strings into an array so then I can work on sorting the array. How can I add strings from a file into an array?
View 4 Replies
View Related
May 12, 2014
I am having trouble in reading data from my text file and print it out exactly like how it looks like in the text file. The problem im having is it will not read the last y Coordinates of the point. it keep reading the second last point for y coordinates which is wrong.
my text file is
0.0 0.0
0.0 1.0
1.0 0.0(but it read until here)
0.0 0.0(suppose to read the last point which is here)
For your information, this is my 1st year degree assignment in C programming. It is to create a program which can read text file (manually create) and print it out in a program and calculate the area for the polygon using ADT function ( .c and .h files)
*This is the code for my read file function*
Basically this accepts a Polygon and a file pointer as parameters. It reads the polygon point data from the file, pass the read data to plg_new() to create a new Polygon and returns the new Polygon created.
Code:
polygon *plg_read(polygon *New_polygon, FILE *Coord) {
int i;
int numberofvertices=0;
int count=0;
char filename[50];
double xCoor[50], yCoor[50];
[Code]....
This is the second function my polygon new code. This ADT function basically creates a new Polygon with malloc(), initialize all ADT data members with its parameter values and returns the Polygon.
Code:
polygon *plg_new(double *xCoordinates, double *yCoordinates, int numberOfVertices) {
int x;
polygon *New_poly = (polygon *)malloc(sizeof (polygon));
if(New_poly->xCoordinates == NULL || New_poly->yCoordinates == NULL) {
free(New_poly);
[Code]....
This is the rest of the code if you need to refer to other codings.
Code:
/**
*@file polygon.c
*@brief Functions for polygon / Struct has polygon numberOfVertices, polygon *xCoordinates and polygon *yCoordinates
*@author: Tan Xian Yao
*@id: 4323440
*@date: 22/04/2014
*/
[Code]...
View 6 Replies
View Related
Dec 24, 2014
I've been experimenting a bit and can't find a decent way to make a brute forcing script that accepts a password from standard input, and goes through all possible combinations until it is matched. How to structure the code?
View 1 Replies
View Related
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
Nov 5, 2013
I am in an "intro" C++ course and am having trouble with a section of my current project.
We are required to open a text file, read the data from that file, and print it back.
However, we are supposed to let the user input the name of the file that is to be opened. This is the code I have so far. It is not opening anything.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int NUM_QUESTIONS = 30;
typedef char CharArray[NUM_QUESTIONS];
string fileName;
[Code]...
View 2 Replies
View Related
May 13, 2012
I am trying to read from a data file that has input as :
12.0, 11, 123
14.0, 12.1, 3
And I want the program to read the data from the file and then make it into an array of structures and then print that array afterwards.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_INPUT 1000
int n =0;
int i = 0;
typedef struct {
double x[MAX_INPUT];
[Code] .....
The program when run gives the following output:
Ishtiaque-Mohammed-Khans-MacBook-Pro:Comp20005 IshtiaqueMKhan$ gcc -Wall -ansi -o ProjectB ProjectB.c
ProjectB.c: In function "main":
ProjectB.c:59: error: incompatible type for argument 1 of "print_array"
View 1 Replies
View Related
Sep 28, 2014
I'm new to programming and i'm trying to do a certain task. I want to use a for loop to read certain data from a txt file and print them to a console. I'm trying to read student names and their grades.
Something like
3 // 3 represents the number of students.
George 97
Sarah 70
Maya 88
The data may vary but it's always in this format.
View 14 Replies
View Related
Mar 8, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
char buffer[256];
FILE * myfile;
myfile = fopen("read.txt","r");
[Code]...
I also got an error in printing wherein the data in read.txt is "Hello" newline "World" and my program prints world twice.
View 3 Replies
View Related
Dec 22, 2013
I need a list generated of all possible subset combinations for the set 1,2,3,4,5,6,7,8,9,10,12. Select six. Numbers cannot repeat.
Example subset: 1,2,3,4,5,6 (six selected, no repeats).
Example of what I dont need: 1,1,2,2,3,3,4,4,5,5,12,12 or 1,1,1,1,1,6.
I will also need the opposites removed, meaning...if I have 1,3,5,7,9,11 then I need 2,4,6,8,10,12 eliminated from the final list.
This is for a game, where you must select all numbers right or no numbers right.
View 2 Replies
View Related
Sep 21, 2014
The code below will generate combinations of numbers from 1 to 25 in an 15 numbers array. The only filter I've applied is that the sum of all the numbers in the vectors divided by 15 needs to be between 13 and 14.
I would like to count how many consecutive numbers there are in one combination, so that later i can apply another filter.. for example:
1 3 4 5 6 8 10 13 14 16 17 18 19 20 25
3 + 4 = 1
4 + 5 = 1
5 + 6 = 1
13 + 14 = 1
16 + 17 = 1
17 + 18 = 1
18 + 19 = 1
19 + 20 = 1
_____________
Count = 8, in this case..
I think it's not very difficult to do, but i just can't see how to do it.
#include <iostream>
#include <vector>
#include <numeric>
[Code]....
View 3 Replies
View Related
Nov 17, 2013
I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort
Code:
void Sort(int ary[], int size)
{
int temp;
int smallest;
int current;
int move;
}
[code]....
put it wont print the numbers sorted when I use my print function, just the unsorted numbers.
View 1 Replies
View Related