For C++, using visual studio. Our professors ask we not use cout or cin, prefera
ID: 665809 • Letter: F
Question
For C++, using visual studio. Our professors ask we not use cout or cin, preferably scanf or gets, or printf
Write a program that allocates (using pointers and malloc) an array of big enough to hold five integers and then allows the user to enter numbers. When the array fills up your program should create a new array with double the capacity and copy the old array into the new array. Allow the user to continue adding numbers until the array is again full. Print the final contents of the array.
(Since we didn't cover linked list in much detail this problem is optional and not required. I would encourage you to attempt it if you have time.) Modify the linked list program to include a search. The search should allow the user to enter a cost and then print out all the part numbers with a cost greater than that value.
Write a program that allows the user to enter the name of a text file. The program should then count and report the number of words in the text file. Assume that all words are separated by one or more spaces. Use the test.txt file in the homework section on Blackboard to test your program.
Explanation / Answer
working c++ code
#include <stdio.h> /* printf, scanf, NULL */
#include <stdlib.h> /* malloc, free, rand */
int main ()
{
int i,n;
int * buffer;
printf ("How many integers you want to allocate? ");
scanf ("%d", &i);
buffer = (int*) malloc (i+1);
if (buffer==NULL) exit (1);
for (n=0; n<i; n++)
buffer[n]=rand()%26;
for (n=0; n<i; n++)
printf ("%d ",buffer[i]);
free (buffer);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.