repost the probram and tell me what line the error is on. If this error is in main() than most likely it's because you have to pass a pointer to A, for example if A is a pointer then
heapInsert(&A, ... )
repost the probram and tell me what line the error is on. If this error is in main() than most likely it's because you have to pass a pointer to A, for example if A is a pointer then
heapInsert(&A, ... )
Hint: The first question, about converting from text 'A' to ascii 65
Every character you can type from the keyboard has a numeric value. See this standard ascii table.. In C and C++ you don't have to do anything at all special in order to convert from 'A' to 65 because the two are the same thing.
char c = 'A';
cout << c << " the ascii value is: " << (int)c << '\n';
It's nothing more than typcasting the char to an int.
move lines 14-23 into a method, you can't have executable code outside functions.
After thinking about it, this might be a bit easier to work with
void heapInsert(int **A, int &size, int Item)
{
size = size + 1;
int i = size - 1;
int *B = new int[size];
memcpy(B, *A, (size - 1)*sizeof(int)); // copy old array to new
while (i > 0 && B[getParent(i)] < Item)
{
B[i] = B[getParent(i)];
i = getParent(i / 2 - 1);
cout << B[i] << endl;
//i = getParent(i);
}
B[i] = Item;
delete[] * A;
*A = B;
}
Yes, some of the other functions will also have to change, especially those called from main()
void heapInsert(int **A, int &size, int Item)
{
size = size + 1;
int i = size - 1;
int *B = new int[size];
memcpy(B, *A, (size-1)*sizeof(int)); // copy old array to new
delete[] *A;
*A = B;
while(i > 0 && *A[getParent(i)] < Item)
{
*A[i] = *A[getParent(i)];
i = getParent(i/2 - 1);
cout << *A[i] << endl;
//i = getParent(i);
}
*A[i] = Item;
}
No one is going to do your homework. Please post the code you have attempted to write and ask specific questions about what you don't understand. Do the assignment one function at a time, don't attempting to write them all at once. Write a little code, compile, correct errors, then repeat until the function is complete.
array B in that function has no value because it doesn't change the size of array A.
In main(), change array A to be a pointer and initially allocate it to contain 10 elements. Then in heapInsert increase the size of A by 1. You will have to change the signature of heapInsert() a little because you have to pass a pointer to a pointer so that heapInert() can change the address of the pointer in main().
void heapInsert(int **A, int &size, int Item)
Difficulty in programming.
Don't feel alone -- that is a common feeling even among experienced programmers. Well maybe there is one exception, our moderator Mike.
Yes, the array has to be dynamically allocated, then in heapInsert() you have to increase the size of the array to accommodate the new element. That becomes much easier and faster if you used a standard tree of allocated nodes instead of putting everything in one big chunck of memory.
Probably because heapInsert() changes the value of size from 10 to 11 and there aren't 11 elements in the array. You can't just arbitrarily change the size of a statically declared array.
Whare does the table already contain? Just add two more columns -- one to count the number of times the member uses the golf course and another to count the number of guests. When a member comes to the golf course look up is row in the table and increment the two columns.
switch statements do not permit ranges, so the only way to do that would be something like this:
switch(qty)
{
case 21: case 22: case 23: case 24: case 25:
case 26: case 27: case 28: // etc etc through 40
discouint = 0.05F;
break;
case 61: case 62: case 63: case 64: case 65:
case 66: case 67: case 68: // etc etc through 80
discouint = 0.10F;
break;
};
And that is just plain STUPID. Much easier to use if statements.
Drugs and gangs are more symptoms of child poverty and unprepared/unequiped parents,
I disagree -- if that were the case then wealthy movie stars such as Michael Jackson wouldn't be using drugs. Drugs are everywhere, not just in proverty strucken areas but also in schools of wealthy parents.
When is a tablet not a tablet but a notebook? I bought my college grandaughter a Microsoft Surface with keyboard about 6 months ago and she loves it, a lot lighter than a notebook and the keyboard is slient. That's really about the only difference between the Surface that I bought here and a standard notebook.
The school system is faulty in not properly ...
Not necessarily -- many kids won't learn, or just simply drop out of school. IMHO drugs in schools has a lot to do with the problem. How are kids supposed to learn anything if they are always high on drugs and/or gang members whose only goal is to make life a living hell for other kids/people.
Also, time.h is only accurate since 1970 (I think that's the beginning date). So if you wanted to calculate how many minutes I've been alive you wouldn't be able to do it with any of the functions in time.h. AFAIK the only way to do that is to use boost time/date c++ class or write your own class.
If I reformat then everyone else who has data on my computer will loose it.
Sorry, but I don't understand the assignment.
"America's 50th celebration.", what 50th celebration? US has been a nation for over 225 years.
The algorithm should accept and store the actual dollar value that will be allocated to the parishes.
US has no such thing as "parishes". A parish is a church taritory. US does not have an official religion. And the US government does not allocate any money to any religious organization. So I have no idea what that statement is supposed to mean.
Where are several books by that author. Which one do you want? I suppose you will have to buy with your money the whole book in order to get just a single chapter.
Interesting article, Mark. I don't really have much of a problem using Windows 8.1, once I got to know where everything is located. I installed the Classic Start 8 which Davy wrote about awhile back.
WOW! Do you really want all the sql servers on the internet??? That could be millions of them.
What are you entering for Input (line 27)? And what are the command-line arguments you are using (argv[])?
I tried to run your program and it crashed upon startup, the reason is that it takes up too much stack space. All those huge arrays are just too much. Move lines 14 and 16 up above main() into global space and the program will run.
line 40: That is a memory leak.
Ignore that comment -- your program is freeing memory correctly.
use strcpy() to copy the tempFile to name. strcpy(fileName[numberFile].name,tempFile);
I'm also running 8.1 Pro.
Because Oct 31 = Dec 25
I don't get it.
P2P-storage is 1000x more secure than cloud-storage will ever be
Now so ? You have no control over data access in either case. (this article). The way I understand it with P2P data is stored on other people's hard drivers all over the world. What happens to that data if I decide to reformat my hard drive? Or just erase the data? Or turn off my computer?
Return type of both is void so don't we have to type cast it ??
No, C language does not require it, but c++ does.
Modern compilers will at least flag the lack of a cast with a warning.
Might be your compiler. Neither gcc (MinGW) nor Visual Studio 2013 produce that warning.
# include <stdio.h>
# include <stdlib.h>
int main()
{
int* x = malloc(10 * sizeof(int));
free(x);
return 0;
}
I briefly scanned the language overview here and I don't see how it will help solve your question. That doesn't mean it won't -- just that how is unclear from what I read.
I just forced Windows Update on my Windows 8.1 PC and I don't have that new start menu. Is that a 3d party Start Menu as in another article you wrote awhile ago?
Line 24 is unnecessary because the string is already null terminated. Also, you are null terminating the string in the wrong place.
line 38: illegal statement. Must be arg[++count][0] = '\0';
line 40: That is a memory leak. tokens is not a simple block of memory. You have to free() each of the pointers individually (see line 71).
line 42 is unnecessary because line 44 strcpy() will start at the beginning of the character array anyway.
line 51: you might try typcasting the last parameter_spawnv(_P_WAIT, prog, (char**)arg))
line 62 and 69: sizeof(*result) will ALWAYS be 1, so using sizeof() there has no value.
Have you tried ComboBox.FindString() ?
cout is defined in <iostream> header file. As a beginner, don't try to read iostream header file -- it's a big mess. Just be aware that cin and cout are declared in iostream. If you want to do file io then use fstream, ifstream and ofstream classes. Trying to follow the header files can ruin your brain.
If you don't know what namespaces are then you need to read a good tutorial because namespaces are fundamental to c++ language. Namespaces were invented to keep from getting name conflicts from one file to the next, that was a big problem in C language. For example, file A.h might declare a struct named foo, and file B.h might declare another structure with the same name. If both files are included in the same *.cpp file then there is a name clash. Namespace helps prevent that problem.
All (or most) standard C++ header files are under the namespace called "std". So when you write using namespace std;
you are telling the compiler to use everything in that namespace regardess of where it comes from. In small pograms like you might write in school that is not a big problem, but in large professional c++ program it can become a problem. There are a couple alternate ways of coding it, such as using std::cin;
or just writing std::cin << "Hello World\n";
Your calculations are incorrect. I changed all doubles to floats so that the compiler wouldn't complain about assigning doubles to floats. And I removed rem_amt variable because it isn't needed.
You need to fix up the last payment because it may be too much, which puts remaining balance negative.
#include <iostream> // for cin, cout
#include <string>
using namespace std;
const float ANN_INTEREST = 0.05F; //simple annual interest rate of 5%
int main()
{
float interest_rate, total_interest_paid = 0.0F, month_interest = (1.0F / 12.0F); //declaration of loan interest rates
float payment, loan, monthly_payment, interest_paid; //monetary values
int payment_count = 1; //declaration of the payment serial numbers
// Welcome message
cout << "$$-$+$-$+$-$+$-$+$-$+$-$$\n"
<< "$$ $$\n"
<< "... Topiloe's Bank ... $$\n"
<< "$$ $$\n"
<< "$$-$+$-$+$-$+$-$+$-$+$-$$\n";
cout << "What is the amount of your loan? ";
cin >> loan;
cout << "What is the interest rate? ";
cin >> interest_rate;
cout << endl;
monthly_payment = loan*ANN_INTEREST;
cout << "Monthly payment on a loan of " << loan << " is " << monthly_payment << endl;
cout << endl;
cout << "Payment Details: \n";
cout << "Payment Number\t" << "Payment Amt\t" << "Interest Paid\t" << "Remaining Balance\n";
cout << "--------------\t" << "-------------\t" << "-----------------\n";
payment = (20.0F / 100.0F)*loan;
interest_rate /= 100.0F;
interest_rate /= 12.0F;
do
{
interest_paid = interest_rate*loan;
loan -= (payment - interest_paid);
cout << payment_count << "\t\t" << payment << "\t" << interest_paid << "\t\t" << loan << endl;
//cin.get();
payment_count++;
total_interest_paid = +interest_paid;
} while (loan …
Maybe paper is better if you are in a place where there is no electricity, such as in a small boat in the middle of the ocean. Kindles need electricity to recharge the batteries.
I don't think you want to use a Kindle in a hot tub:) A little like using a hair drying in one. Not very smart thing to do.
either forum would be a reasonable place to ask
Not really -- the question is not related to compute languages.
floats and doubles can't be eaily compared for equality due to rounding errors in memory. Read this related thread
Displaying the ascii value is simple -- just typecast it from int to char.
What compiler are you using? I tried that and got two different addresses.
I prefer ebook because I can change the font size to whatever I like, because ebooks aren't as heavy as paper books, and because people don't chop down any trees to create ebooks.
Yes, but the numbers are all in ascending order if you read the lines from top to bottom, ignoring the arrows. It should be rather trivel to add the arrows.
1 2 3 4
5 6 7 8
9 10 11 12
The flaw in my approach is if the data is in some random order in the output
1 4 2 3
9 10 7 8
11 5 6 12
If that is possible, then you can't use my suggestion.
Maybe you did something wrong. This is what I get
00AFFF10 00AFFF04
Press any key to continue . . .
#include<iostream>
using namespace std;
int main(){
int fish = 6;
int * fishp = &fish;
cout << fishp << ' ' << &fishp << endl;
return 0;
}
Are you trying to do this? cout << fishp << ' ' << &fish << endl;
Then yes, they will both be the same because fishp points to &fish.
line 121: You can not test two floats or doubles for equality due to possible rounding errors in memory variable. For example if you assign the value 5.5 to a float, in memory it might actually be 5.500001.
One way to handle that is to use integers instead of floats. So if you want 1 decimal place then multiply the float by 10 and assigne it to an integer. Then you can safely use equality tests on the integers.
Here is another thread on that very topic.
line 240: Suggestion: Save yourself a lot of grief by shortening that path down. In Visual Studio you can move the projects to another folder. I always put projects in a folder directly off c:, such as c:\dvlp
That makes it a lot easier to specify specific project paths.
line 244: how do you know there will be at least 10 lines in the file? What if there are only 5, or there are 50? A more general way to code it without knowing beforehand how many lines are in the file is like this:
int i = 0;
while(getline(inFile, line))
{
list[i] =::atof(line.c_str());
x.InsertItem(list[i]);
++i;
}
Or even better yet
int i = 0;
while(infile >> list[i] )
{
x.InsertItem(list[i]);
++i;
}
Why do you need float list[10]
? You can just insert it directly without first reading into list.
float n;
while(infile >> n )
{
x.InsertItem(n);
}
you could code it: while (rem_bal > 0.0)
That isn't, what i said was to sort it in ascending order because the final output is in ascending order.
LINE 33 is doing integer division which means there are no decimals. So 20/100 is 0. You need to use float, for example20.0/100.0