How can I find the executable file
You could just use File Explorer, enter the program name in the search bar, and let File Explorer find it for you.
How can I find the executable file
You could just use File Explorer, enter the program name in the search bar, and let File Explorer find it for you.
It's almost impossible to test for equality with floats because the varables can contain small rounding errors. It is better to convert both floats to strings then compare the two strings. You might also be able to use floor()
No one here is going to write your program for you. Here are some basic steps needed to complete your assignment.
Step 1: create a structure that contains all the information you need to store in the file.
Step 2: populate the structure with the data
Step 3: using std::ofstream open a file for binary writing
Step 4: call std::ofstream's write() function to write out the structure in binary form. It will write the structure all in one big chunck of data exactly as it appears in memory. repeat this as often as necessary to write out all the structures.
Step 5: close the output file that was opened in Step 3.
Step 6: To read the file, open an std::ifstream for reading in binary mode
Step 7: Call std::ifstream's read() function to read the structure(s) written in steps 3-5.
Here is a complete list of the available time functions. When to use what all depends on what you want to do.
delete line 30, it's already reading the file in line 27.
Post the function that writes the file.
A lot easier way to do it is to read/write binary files instead of text files using fwrite() and fread(). You write the entire structure as one chunk that way. But don't expect to view the file with a text editor such as Notepad.
I worked on such a project about 10 years ago, I was one of a team of nearly 100 people and it took about 3 years.
The program is doing integer division which means no fractions because number1 and number2 are both integers. You can correct the problem by typcasting either the numerator or demoninator to float
correctanswer = (float)number1 / number2;
The difference between char *str="Hello World!!";.
and char str[]="Hello World!!";.
is that char* str is just a pointer into read-only memory where the string "Hello World" is actually stored, it's contents can not be changed. char str[] makes a copy of the string and puts it into read/write memory where you can change the string nowever you wish -- you just can't change the length of the string. Using gets() on char str[] works just fine as long as you don't enter more characters then there are in the original string.
You can't use char* str with gets() because char* str had no memory allocated to it. Where is gets() supposed to put the characters you type? It is YOUR responsibility to entire that the string you pass to gets() has enough memory allocated to it to hold all the characters you want to type. And that is a big big problem with gets() and why everyone discourages it's use in most programs. instead of gets() use fgets() instead because fgets() limits the characters you type to the size of the buffer.
In lines 30-32 I think your trying to find out if a<b<c. if( a%b > 0 && b%c > 0) then a<b<c. So line 31 is backwards, should be b%c not c%b.
line 34: That is doing integer division which means no fractions. 3/4 == 0 not 0.75. Convert either the numerator or denominator to float
x = (float)sum/(c*c);
And x should be declared as float, not int.
To determine if a<b<c why not just use the normal simple if statement
if( (a < b) && (b < c) )
{
// true
}
then to determine if they are Pythagorean Triple:
if( (a*a) + (b*b) == (c*c) )
{
// true
}
Sounds like the console window is closing and killing the mp3. Add a PAUSE in the batch file after the line that plays the mp3 to keep the console window open while the mp3 plays.
what do you expect? Your pogram is generating 30 random numbers that are between 1 and 30.
Is it possible to create tables in the text editor that will retain spacing -- something like code tags but without line numbers?
The mode is the number that appears the most often in the array. If the array contains {1,2,1,3,4,5,8} the mode is 1 because it appears twice and all others appear only once.
One way to calculate the mode is to use another 2d array, the first dimention contains a value from the original array and the second dimention contains a count of the number of times it appears in the original dimension.
Using the previous example data, the 2d array would contain
1 2
2 1
3 1
4 1
5 1
8 1
Now all you have to do is select the value from the 2d array that has the largest count value.
I think you can remove the warning by initializing those two pointers to NULL when they are declared on lines 18 and 19.
So why shouldn't I put everything in PCHs?
That is a compiler-generated file, you can't do anything with it except delete it when it's no longer needed.
Everything in stdafx.h is included in precompiled headers.
Yes, the linker only links into the executable the functions etc. that are actually referenced in the program or one of the libraries that the program uses. It's just standard, normal linking and is the same with or without precompiled headers.
I assume you are using one of the Microsoft c++ compilers. If you want precompiled headers then every *.cpp file in the project must include stdafx.h as the first header file. You can include any others you want after that.
#include "stdafx.h" // precompiled header file goes first
#include "myclass.h" // now all others you want
#include "anotherclass.h"
Your project will also have stdafx.cpp, which is the first *.cpp file that the comopiler will compile, and the compiler generates the *.pch file at that time. The *.pch file contains all the pre-processed files that are in stdafx.h. This greatly speeds up the compilation of large projects because the compiler doesn't have to read all the includes for every *.cpp file.
Precompiled headers do not work the C programs, it's C++ only. If your project is a mixture of both c++ and C files then you will have to manually turn off precompiled header options for all the C files.
It worked for me
Enter size of array:
5
Enter elements: 1 2 3 4 5
The elements after shifting the array:
0
1
2
3
4
5
Press any key to continue . . .
What did you do about it?
pritaeas just deleted a duplicate post of mine and now the post reply count is 0 even though there is still 1 reply. I recall someone else reported the same issue a few days ago.
There are millions of examples of how to connect to Microsoft Access database,
ODBC is probably the oldest and most widely used database api in use. Here is a google list of tutorials.
Then there is the Microsoft ADO DLL, I think it's the same as you use in VB. Here are some links for it.
Some database makers also have c and c++ api functions specific to their databases, such as MySQL++ for MySQL database.
If you don't yet know SQL (Structured Query Language) then see some of these tutorials.
In the loop on lines 4-8, where is buffer incremented? line 4 always looks at the same character, which is why it's an infinite loop, unless buffer[0] == '\0'
Try this loop
while(buffer[a] != '\0')
{
cout << buffer[a];
a++ ;
}
The problem is in Data constructor, you didn't initialize Values and Length so alloc() attempted to delete Values when it had a random value.
Data(const Data& d) {
Values = 0;
Length = 0;
alloc(d.length());
for (unsigned long CountData = 0; CountData < d.length(); ++CountData) {
Values[CountData] = d[CountData];
}
};
Data& operator=(const Data& d) {
if (this != &d) {
alloc(d.length());
for (unsigned long CountData = 0; CountData < d.length(); ++CountData) {
Values[CountData] = d[CountData];
}
}
return *this;
};
Your program looks correct -- what are you confused about?
Please post the steps you took to produce the error. Which menu items did you select, and what did you enter. Better yet, get a screenshop of the console window that contains all the information and post it here. I compiled your program with VC++ 2014 and it compiled without errors or warnings, then ran it, but I don't know what you did to get the error.
Yes, the text files normally include '\n' as a line separator. Here's one way to do it one character at a time. I didn't compile or test this code, so I hope it doesn't contain any errors.
char line[80] = {0};
char ch;
int counter = 0
while( infile >> ch ) // read the entire file
{
if( ch != '\n' && counter < sizeof(line) )
line[counter++] = ch;
else
{
line[counter] = '\0'; // null terminate the string
cout << line << '\n'; // display the line
counter = 0; // get ready for next line
}
}
// last line of the file
line[counter] = '\0'; // null terminate the string
cout << line << '\n'; // display the line
counter = 0; // get ready for next line
line 50: this->i=2;
since i is private derived classes cannot change it's value.
You need to change base::set() (line 9) to accept an integer, then derived classes can call public set() to change the value of i.
Just call getline() which will do all that for you.
ifstream in("filename.txt");
char buf[80];
while( in.getline(buf,sizeof(buf)) )
{
// do something
cout << buf << '\n';
}
At one time there was a link at the bottom of the page to all the archived newsletters. I haven't seen it for a long time now. Too bad.
I've also seen copyright to include the original copyright date as well as the year, such as Copyright 1990-2014
When p is an integer pointer then p++ incrments by sizeof(int), not by sizeof(int *), and the code he posted proves it. Had p been a pointer to an array of char, then p++ would have incremented by sizeof(char), or 1.
Although what you said is correct, the question was why did the pointer increment by 2 instead of 4, which is not the same as the answer you provided. I think you misunderstood the question. In the question, the number of bytes by which the pointer is incremented is the sizeof one element of the array.
you can easily find out the size of an int by printing sizeof(int) -- but to answer your question, on most 32-bit compilers sizeof(int) == 4. If you are accustomed to using Turbo C, that is a 16-bit compiler and sizeof(int) == sizeof(short) == 2. But on most modern compilers sizeof(int) is not the same as sizeof(short). It's never a good idea to outguess the size of integers becaue it can vary from one compiler to another, and the C standards make no such assumption.
printf("sizeof(short) = %d\n", sizeof(short));
printf("sizeof(int) = %d\n", sizeof(int));
printf("sizeof(long) = %d\n", sizeof(long));
printf("sizeof(long long) = %d\n", sizeof(long long));
That was the year Dani copyright the web site, not the current year. All coptright notices are like that.
Snowed again last night, only a couple inches though.
what you want is something like this:
char i2DArray[5][20]
That will hold 5 names, and each name can be up to 20 characters long.
Then on lines 13-17: Note that you only need one loop, not two loops.
for ( y = 0; y < 5; y++){
printf("Enter the name of your friend: ");
scanf("%s", i2DArray[y]);
}
The question makes no sense.
Beginning with Office 365 (released 2013) it is subscription based, about $150.00 USD per year for 5 licenses and includes all Office programs. Previous versions of MS Office are not compatible with Windows 8/8.1. And it no longer is available on DVD -- download only from MS web site.
Although OpenOffice and LibreOffice are free their features aren't nearly as good as MS Office 365, and the files aren't compatible.
Thanks everyone. And Happy BD Mike S. :) You're about the same age as my grandson, who recently joined the US Army and now gets to drive around Bradley tanks for fun :)
I have another birthday anniversary today, I'm now only 39, with 32 years of experience.
line 16: I'd use int instead of double because there is no need for decimal places.
lines 17-31: remove the commas, numeric literals must not contain commans.
Also, add a comma after each of those lines, then add a semicolon after the last one.
const int
Mustang = 55000,
Harley Davidson=49000,
Jeep =35000,
Sasuki= 31000;
lines 23-26: variable names can not duplicate those in lines 17-31. Use some other names. But you don't need them at all because they are never used in the program, do just delete those lines.
switch statement: you need a break statement as the last like of each case. Without the break all the other cases will also get executed.
your program is not reading anything so fin.eof() never happens.
The file is open for writing only. fscanf() is a read function. Solve the problem like this:
line 9: open the file with "rw" flag
line 15: uncomment that line.
add a new line just before line 15: fflush(fp);
which will force everything to be physically written to disk. Until then the data could be just cashed in memory.
please explain why you think something is wrong?
There already is one split -- Games
You have break statements in the wrong place.
Move the break statement on line 42 down to line 71.
Move the break statement on line 78 down to just below line 98.