Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
complete the TODOs in C++
#include <iostream>
#include <fstream>
using namespace std;
//Uncomment the lines and implement the TODOs in the resizing logic
int* resize(int* arrayPtr, int &capacity)
{
// TODO increase the capacity by two times
// int newCapacity =
// cout<<"Resizing from "<<capacity<<" to "<<newCapacity<<endl;
// TODO dynamically allocate an array of size newCapacity
// int *newArray =
// TODO copy all data from oldArray to newArray
// TODO free the memory associated with oldArray
//capacity = newCapacity;
// TODO return the newArray
}
int main(int argc, char* argv[])
{
if(argc != 2)
{
return -1;
}
stringfilename = argv[1];
ifstreamdata;
data.open(filename.c_str());
intcapacity = 10;
int *arrayPtr;
// TODO Dynamically allocate space here for the array
//arrayPtr =
intnumOfElement = 0;
stringtemp;
if(data.is_open())
{
while(getline(data, temp))
{
inttoBeInsert = stoi(temp);
if(numOfElement == capacity)
{
// Complete this function
arrayPtr = resize(arrayPtr, capacity);
}
arrayPtr[numOfElement] = toBeInsert;
numOfElement++;
}
data.close();
}
for(inti = 0; i < numOfElement; i++)
{
cout<<"Num: "<<arrayPtr[i] <<endl;
}
return0;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Problem 1. In C/C++ programming language, write down the lines of codes (and figure) to show -(a) assignment-by-sharing(b) dangling referenceProblem 2. Show the correspondingcodecontents in memory for themainmethod and draw thestackcontents while themainmethod starts execution and reaches at line 12. 1 #include<iostream> 2 using namespace std ; 3 int main () 4 { 5 int i ; 6 short j ; 7 char k ; 8 i = 30; 9 j = i ; 10 k = ( char ) j ; 11 i = k ; 12 13 return 0; 14 } Problem 3. (a) In C++, write down themainmethod including aforloop. The body of theforloop includes the followings :anifconditionan array (of any type & of any size)a structure variable (with at least two variables of any type) (b) Show the correspondingcodecontents in memory for themainmethod and drawthestackcontents while themainmethod starts execution and reaches at theline prior to return from yourmainmethod of Problem 3(a). (c) Create a symbol table structure (dynamic scoping) at the line before…arrow_forwardInstructions for both assignments can be found in the picture linked to this post. The programs must be written in c++ and requires that the random number generator be seeded like this program: Program 3.25 // This program demonstrates random numbers. #include <iostream> #include <cstdlib> // For rand and srand #include <ctime> // For the time function using namespace std; int main() { // Get the system time. unsigned seed = time(0); // Seed the random number generator. srand(seed); // Display three random numbers. cout << rand() << endl; cout << rand() << endl; cout << rand() << endl; return 0; }arrow_forwardConvert the following C++ programs into Pep/9 assembly #include <iostream> using namespace std; void minimum (int i1, int i2){ if (i1 < i2) cout << i1 << " is less than " << i2 << endl; else if (i1 > i2) cout << i2 << " is less than " << i1 << endl; else cout << i1 << " equals " << i2 << endl;}int main (){ int n, m; cout << "Enter two integers: "; cin >> n >> m; minimum (n, m); return 0;} Submit: Pep/9 source code along with screen capture showing it running in the Pep simulatorarrow_forward
- In C programming!! Function prototype and implementation for the calculateDivisors function that takes in an integer parameter, calculates the sum of its divisors, and returns that sum (as an integer value) A structure that represents what is represented on each line of output, e.g., o Linenumbero Sumofthedivisorsforthatlinenumbero Characterarraycontaining“Perfect”,“Deficient”,or“Abundant” Pointer declared within the main that will be used to point to an area of memory containing a collection of these structs Dynamically allocated memory for the number of structs necessary You will assign values to each struct via the pointer A loop that goes from X to Y, where X and Y are the numbers inputted by the user at the command line argumento Note:becausetheuserisenteringinputhere,youwillneedtocheckforreasonableness: § The value of X must be greater than or equal to 2§ The value of Y must be greater than the value of X§ If either one of the above conditions are not met, you should…arrow_forwardConvert the following C++ programs into Pep/9 assembly #include <iostrea> using namespace std; int minimum (int i1, int i2){ if (i1 < i2) cout << i1 << " is less than " << i2 << endl; else if (i2 < i1) cout << i2 << " is less than " << i1 << endl; else cout << i1 << " equals " << i2 << endl;}int main (){int n, m;cin >> n >> m;cout << "Minimum: " << minimum (n, m) << endl;return 0;} Submit: Pep/9 source code along with screen capture showing it running in the Pep simulatorarrow_forward8.arrow_forward
- Solve in C++ using the given code and avoid using vectorsarrow_forwardZybooks C++ 1.7 LAB: Introduction to data structures labs Step 1: Producing correct output Three commented-out lines of code exist in main(). Uncomment the lines and click the "Run program" button. Verify that the program's output is: 2 + 2 = 4 Unknown function: PrintPlus2 Secret string: "abc" Submit your code for grading. Your submission will pass the "Compare output" test only, achieving 1 of the possible 10 points. Step 2: Inspecting the LabPrinter class Inspect the LabPrinter class implemented in the LabPrinter.h file. Access LabPrinter.h by clicking on the orange arrow next to main.cpp at the top of the coding window. Member functions Print2Plus2() and PrintSecret() print strings using std::cout. Step 3: Implementing CallFunctionNamed() Remove the three uncommented lines from main(). Then implement the CallFunctionNamed() function in main.cpp to handle three cases: If functionName is "Print2Plus2", call printer's Print2Plus2() member function. If functionName is "PrintSecret",…arrow_forwardData Structure Using C++ I need a function like this ::: float postfixEval(string postfix) {int a, b;stack<float> stk;string::iterator it;for(it=postfix.begin(); it!=postfix.end(); it++) {//read elements and perform postfix evaluationif(isOperator(*it) != -1) {a = stk.top();stk.pop();b = stk.top();stk.pop();stk.push(operation(a, b, *it));}else if(isOperand(*it) > 0) {stk.push(checkNumber(*it));}}return stk.top();} to evaluate postfix with more one digit in expression (multi digits) please just this function simple like the abovearrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education