Note: Could you plz go through this code and let me know
if u need any changes in this.Thank You
_________________
// numData.txt
45
56
67
78
89
99
88
77
66
55
44
33
22
11
17
73
39
98
_________________________
#include <iostream>
#include <fstream>
using namespace std;
//constants
const int CAP = 100;
//function prototypes
bool openFile(ifstream &);
void readData(ifstream &, int [], int &);
void printData(const int [], int);
void evenCount(const int[], int);
void insertItem(int[], int &, int, int);
int main()
{
ifstream inFile;
int list[CAP], size = 0;
if (!openFile(inFile))
{
cout << "Program terminating!! File not found!" <<
endl;
return -1;
}
//read the data from the file
readData(inFile, list, size);
inFile.close();
cout << "Data in file:" << endl;
printData(list, size);
//insert a few items
insertItem(list, size, 15, 5);
cout << "Inserted in position 5:" << endl;
printData(list, size);
insertItem(list, size, 101, 2);
cout << "Inserted in position 2:" << endl;
printData(list, size);
insertItem(list, size, 215, 12);
cout << "Inserted in position 12:" << endl;
printData(list, size);
//call the evenCount function
evenCount(list, size);
//end program
cin.ignore(100, '\n');
cout << "Press any key to continue...";
getchar();
return 0;
}
//function to open file
bool openFile(ifstream &inFile)
{
inFile.open("nosData.txt");
if (!inFile)
{
return false;
}
return true;
}
//reads the data from the file
void readData(ifstream &inFile, int list[], int
&size)
{
while (inFile >> list[size])
{
size++;
}
}
//print the contents of the array
void printData(const int list[], int size)
{
for (int i = 0; i < size; i++)
{
cout << list[i] << endl;
}
cout << endl;
}
//insert an item (newNum) in the given position (newPos)
void insertItem(int list[], int &size, int newNum, int
newPos)
{
//insert code here
if(newPos<size)
{
list[newPos]=newNum;
}
else if(newPos>size)
{
list[newPos]=newNum;
size++;
}
}
//count the even numbers in the list and output in this
function
void evenCount(const int list[], int size)
{
int cnt=0;
for(int i=0;i<size;i++)
{
if(list[i]%2==0)
{
cnt++;
}
}
cout<<"No of even numbers in the list
:"<<cnt<<endl;
}
________________________
Output:
________________________Thank You
//This program is your final exam. //Please fill in the functions at the bottom of the...
//This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...
#include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...
This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and unorderedArrayList templates that are attached. Create a header file for your unorderedSet template and add it to the project. An implementation file will not be needed since the the new class will be a template. Override the definitions of insertAt, insertEnd, and replaceAt in the unorderedSet template definition. Implement the template member functions so that all they do is verify that the...
c++ /*This is the starter file for your final proficiency test This program has a function that will generate a list of integers using the rand function. Your job is to fill the insertNum and oddCount functions.*/ #include <iostream> #include <ctime> using namespace std; //constants and function prototypes const int CAP = 100; int buildList(int[], int size); void printList(int[], int size); //your functions to implement /*This function finds even numbers in the list, and inserts a number before the even...
Requirements: Finish all the functions which have been declared inside the hpp file. Details: string toString(void) const Return a visible list using '->' to show the linked relation which is a string like: 1->2->3->4->5->NULL void insert(int position, const int& data) Add an element at the given position: example0: 1->3->4->5->NULL instert(1, 2); 1->2->3->4->5->NULL example1: NULL insert(0, 1) 1->NULL void list::erase(int position) Erase the element at the given position 1->2->3->4->5->NULL erase(0) 2->3->4->5->NULL //main.cpp #include <iostream> #include <string> #include "SimpleList.hpp" using std::cin; using...
The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function so that it is written as a value returning function, returning the required item. If the location of the item to be returned is out of range, use the assert function to terminate the program. note: please give all code in c++ below is the class and implementation(a test program would be helpful in determining how to use it): class arrayListType { public: ...
C++ Modify this program (or create your own) so that it performs the following tasks: 1. Insert the numbers into the list in sorted order (ascending). This will require you to keep the list sorted as you continue to insert new numbers. 2. When adding a new number, first check to see whether it is larger than the last number currently in the list. If it is, add it directly to the end of the list, i.e., do not traverse...
Data Structures and Algorithms C++: I'm having a hard time getting my main.cpp part of the source code (shown below) to output the following: Inserting elements to array list: The list contains 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Deleting elements: The list contains: 2 4 6 8 10 12 14 16 18 20 22 24 this is a programming problem in...
Follow the TODOs and complete the insertItem(), searchItem() and printTable() functions in hash.cpp. The hash function has already been implemented for you. // hash.CPP program to implement hashing with chaining #include<iostream> #include "hash.hpp" using namespace std; node* HashTable::createNode(int key, node* next) { node* nw = new node; nw->key = key; nw->next = next; return nw; } HashTable::HashTable(int bsize) { this->tableSize= bsize; table = new node*[tableSize]; for(int i=0;i<bsize;i++) table[i] = nullptr; } //function to calculate hash function unsigned int HashTable::hashFunction(int key)...
Hi there, I am working on a binary search tree code in c++. The program must store and update students' academic records, each node includes the student name, credits attempted, credits earned and GPA. I have made some progress with the code and written most of the functions in the .cpp file (already did the .h file) but i am struggling with what to put in the main and how to put an update part in the insert function. I...