C++ :: Determining Index To Place New Value
Dec 9, 2013
I need function to determine where to place new element in sorted array. I want to use binary search to find index where element should be placed, when push all others.
Prototype should be something like
int WhereToPlaceElement(ElementType hash); // uses private atribute ElType** elements
I have tried my best to write, but all tries ended in inf loops and reading invalid locations of array.
View 3 Replies
ADVERTISEMENT
Oct 22, 2013
determining if a value entered in loop is an odd or even number. Also, the value can't be int because it may be a decimal value(therefore i cant use the if(x%==0).
I need to replace the if(value%2 ==0) else num_even++ statement in my code with something else that will work with float to determine odd vs even.
#include <iostream>
using namespace std;
int main() {
int num_values;
float sum_values = 0;
int num_neg_values = 0;
int num_pos_values = 0;
[code]....
View 1 Replies
View Related
Dec 8, 2013
I am trying to extract the numbers from Numbers.txt, and then put them in the correct file, either Odd.txt or Even.txt, depending on what they are. And I have gotten to a point where I am not sure what to do; right now it just reads Numbers.txt and then the program ends.
#include <iostream>
#include <fstream>
#include <string>
[Code].....
View 2 Replies
View Related
Oct 24, 2013
char A[]={}; this is the array in c++ of unknown size, now I want to enter some alphabets via loop and want to be the no. of elements i entered the size of the array. .
View 8 Replies
View Related
Oct 7, 2014
I am new at c++ and I am trying to write a code to determine the maximum deflection at the end of a cantilevered beam. I am given the formula : deflection= (4 W L^3)/(E B H^3) where W is the load weight, L is the beams length, E is the modulus of elasticity, B is the beams base, and H is the beams height.
// Included Header Files
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cstdio>
[code]....
View 2 Replies
View Related
Feb 16, 2015
i have to read a file with between 5 and 10 pairs of numbers, each on a different line. i can read the file, and wrote something to save the length of the file as a variable, but when i use it i start returning crazy data. the problem is in the do while loop and i want to change the i< in the for loop to "lines" so the code stops when the last digit is read. if i use i<10 the file has extra digits is the file is only 8 or 5 pairs of numbers.
FILE *Fpointout;
FILE *Fpointin = fopen ("test.txt","r"); //read this one
Fpointout = fopen ("out.txt","w"); //write this one
if (Fpointin == NULL) //if no file in source {
printf ("File does not exist."); //tell user it is not there
[Code] .....
View 4 Replies
View Related
Oct 17, 2014
I have to make a program to read a file with strings and determine if they are palindromes. The problem is that the program says that they're all palindromes.
int main() {
ifstream inFile;
ofstream outFile;
inFile.open("in.data");
outFile.open("out.data");
if (!inFile || !outFile) //to display error if input files are invalid
[code]....
View 3 Replies
View Related
Oct 13, 2014
I am trying to write a function that determine if a file in a directory is of a gif/bmp/png/jpg extension. Right now I think I have correctly written my code all the way up to listing the files in the directory and opening them in binary mode.
Now, I am struggling with figuring out how to determine what extension the image is. Right now i am just focusing on writing my "bool isGif();" function... To determine if a file is a .gif extension using binary, the first 6 bytes of the file will contain either GIF87a or GIF89a.So, to do this I would read the first six bytes of the file using the function below, correct?
fin.read((char *) &a_file, 6)
Then, once I read in the first six bytes how would I conditionally compare it to determine if it is a .gif? Would I just use
if(fin == "GIF87a II GIF89a) {
\do something here
}
Because that doesn't seem to be working...
View 13 Replies
View Related
Jan 12, 2014
I was browsing the web looking for simple yet fun programming challenges and crossed this one. I figured out how to reverse the string in place but I want it to read "blue is house the". I approached it in two ways for the heck of it. My idea was the second one, the first one I googled. I didn't know a simple rbegin() could do that, pretty neat.
I found the question here.[URL] ....
Code:
#include <iostream>
#include <string>
int main(int argc, const char * argv[])
{
std::string phrase = "The house is blue.";
[Code] ......
View 8 Replies
View Related
Aug 25, 2014
I have an issue with my codes as according to what I created the fitness level have to appear right after I enter the time take to 3 miles. However it only appears once after repeating five times.
My codes
#include <iostream>
#include <iomanip>
#include <string>
[Code]....
View 6 Replies
View Related
Feb 1, 2015
When I drag a control onto the Xamarin studio layout the control just slides back into the toolbox again. The only way to add controls is to edit the .axml file which is not at all ideal.
I have tried re-installing all the components again multiple times and even tried out using a different computer, still no luck. How to use the mono framework on the Visual studio IDE and build the apk using Xamarin studios?
Details -
Xamarin studio 5.7
Tested on Windows 8, 8.1 and 7
View 10 Replies
View Related
Oct 27, 2013
I have created this code; it is a taxi management system. I've made a class 'List' which handle a linked list structure of the waiting taxis and waiting passengers. The class has a public int variable: waiting, which keeps track of the number of waiting taxis/passengers.
#include<iostream>
using namespace std;
class Queue{ //Class for indivdual taxis and passengers, which will be members of linked list.
public:
string id;
Queue *next;
Queue (){
[Code] .....
But when I run the code and type in a new taxi number, the code does not increment the number of taxis by one the linked list by one. I can't seem to find the problem.
BTW, in the 'int main', I've added "<< taxi_list.waiting" at the end of the line after the user inputs the new taxi registration number, so that I can see how many taxis are now on the list. This is what is being shown as zero, no matter what.
View 2 Replies
View Related
Oct 19, 2014
I have to place two asterisk triangles on top of each other BUT only using 3 for statements. I have gotten the first one:
for(int a=1;a<=10;a++) {
for(int b=1;b<=a;b++)
cout << "*";
cout << endl;
}
I need the output to look like this:
*
**
***
****
*****
******
*******
********
*********
**********
*
**
***
****
*****
******
*******
********
*********
**********
The only kicker is I can have a total of 3 nested for loop statements.
View 7 Replies
View Related
Oct 15, 2014
The question I am given is this:
Given a line of words (total character number is less than 100,
start from odd position 1,
and end with newline char "
").
Write a program to reformat it that new output is formed by each char from its odd position first, then its even position char.
View 14 Replies
View Related
Feb 3, 2014
I have a text file that ifstream opens and fills some fields with the data. I've been able to get at the file, by using the precise path, but that path would be incorrect on other computers I'll be working on the project at. So, is there default location I should drop the folder in, and route to with the path? If not which Directory listing in Visual Studio 2013 should I use so the project can find the folder?
This is how I've formatted the string for ifstream.
".DataSampleActorData.txt"
View 6 Replies
View Related
May 31, 2014
I'm trying to make a program to check if a number has decimal place, for instance: 1.34(yes), 1.0(no), 3.45(yes), 5.0(no).
Code:
#include <stdio.h>
#define LENGTH 4
int main( void ) {
int i;
float a[LENGTH];
for(i=0; i < LENGTH; i++) {
scanf("%f", &a[i]);
[Code] ...
I'm getting this output, why?
Quote
error: invalid operands of types "float" and "int" to binary "operator%"
View 3 Replies
View Related
Oct 3, 2014
This is in-place merge sort, for merge function.
LinkedListNode::LinkedListNode(int value) {
this->next = NULL;
this->value = value;
}
LinkedListNode *mergeSortedLinkedLists(LinkedListNode *firstList, LinkedListNode *secondList)
[Code] ....
View 3 Replies
View Related
May 9, 2013
The best I could come up with is this.
while(true){
wisdomCnt++;
_stprintf_s(szBuffer, _T("%i"), wisdomCnt/10000);
TextOut(hdc,120,10,szBuffer, _tcslen(space));
}
but the program is constantly loading and clicking anywhere causes it to stop responding. Is there a better way to do this especially in Win32 API?
View 6 Replies
View Related
Jul 31, 2013
I am trying to place a counter to count in each time a new order comes in, but I am having trouble with the memory allocation part.
I allocate memory to take in names each time an order comes through, but when I print out the names, I get 0x100103ae0....
View 13 Replies
View Related
May 3, 2014
Assume you want to read from a file and place the data from the file into an array. The array can hold 10 integers. The file may contain any number of integers with 1 integer per line. Fill in the missing loop test condition so that we will read from the file until either end of file occurs or the array is full. Note we are using cin to read from the file since input redirection is being used.
cin >> temp;
arrayIndex = 0;
while ( _____________________________________) {
array[arrayIndex] = temp;
arrayIndex++;
cin >> temp;
}
View 2 Replies
View Related
Mar 1, 2014
I am having problems figuring out how to place a list of strings from a text file into a multidimensional array that is something like words[NUM_WORDS][MAX_LEN]. I already run through the file once and count the number of words in it. I have tried a number of loops using fscanf and fgets, but I'm not sure if I am using them right -- this is my first time using them. The text file is a list of words in a dictionary, so the wordCount is about 45340.
Here is my code:
#include <stdio.h>
#include <string.h>
#define MAX_LEN 46
int main(){
int wordCount = 0;
FILE *inputFile, *outputFile;
[Code] ....
Like I said, the wordCount portion works. I added the printf statements at the end to see if anything was being saved, but it just prints two new blank lines. New to file reading and writing.
View 3 Replies
View Related
Feb 12, 2013
I have used the following code to attempt to place a binary array into and then retrieve from the Registry. I am a member of the local Administrator group. I have verified that the Registry for the app has a binary array 32 bytes in length under the key "settings" / "keyb" ab 12 cd ...
Code:
// in header
unsigned char m_key[32];
int m_nKeySize;
// in implementation
// int ctor
AfxGetApp()->GetProfileBinary(_T("settings"), _T("keyb"), (LPBYTE*)&m_key, (UINT*)&m_nKeySize);
// in OnDestroy
AfxGetApp()->WriteProfileBinary(_T("settings"), _T("keyb"), (LPBYTE)&m_key, m_nKeySize );
Here is a copy of the binary array in the Registry:
7D DE 2B 30 E7 06 12 AC 99 60 8C 26 21 FC 8E 5B 66 DB 72 9E A2 00 BE 15 E1 8B 67 31 E5 EC 8B 15
Here is the binary key retrieved from the Registry using the code above:
D0 EB 26 00 CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC
View 7 Replies
View Related
Mar 5, 2013
I have to make a 8-puzzle and I got the algorithm i just dont know how to restart the program every time i type the move of the blank place in the 3x3 puzzle so i dont have to make 10000 lines to solve the puzzle
View 2 Replies
View Related
Nov 27, 2013
How do I write a ROM BIOS routine which accepts a row number from the user and place the cursor to the beginning of the row number which the user gave?
View 2 Replies
View Related
Dec 31, 2012
I'm new to c++ and I want to create an infinite sheet on which a user could be able to write notes and place images. Any GUI library that I could use to do that?
View 2 Replies
View Related
Aug 8, 2014
How can I create in my C++ program so a user can paste a text and then choose a character on specific line and place?. The above thing isn't that important. I just want to place a character on a specific line and place.
I mean something like this:
Enter a character:
You choosed " / "
On which line do want the character?
You choosed "Line 1 and 2"
Where do you want the the to appear on the line? (left or right)
You choose left.
Results:
Line 1. / hello
Line 2. / hello
View 8 Replies
View Related