How to Create a Test File in C++ PDF

Verified

Added on  2022/07/27

|8
|1260
|40
AI Summary

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Running head: COSC2140
COSC2140
Name of the Student
Name of the University
Author Note

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
COSC2140 1
Table of Contents
Introduction:...............................................................................................................................2
Linked list:.................................................................................................................................2
Binary search tree:......................................................................................................................2
The code:....................................................................................................................................3
Output:........................................................................................................................................4
Output file:.................................................................................................................................5
Hash Map:..................................................................................................................................5
Conclusion:................................................................................................................................6
References:.................................................................................................................................7
Document Page
2COSC2140
Introduction:
The purpose of this project is to create a test file in c++. The program will take input
from a text file and it will print that output in another text file.
Linked list:
The Linked list is a linear data structure for storing the data elements. The data
elements that are stored in linked list memory location, are linked contiguously. It consists of
node. Each node acts as the container of the data field and reference links to the next node in
linked list. By using the pointer the data elements are linked together that represents a
sequence. It is the features that gives the allowance for insertion and deletion operation in
efficient manner. The first node of the linked list is known as head. Having no data elements
in the linked list then the value of head is considered as NULL.
It is similar to array. Actually linked list is a dynamic data structure. With the time it
can be shrined. There is no necessity for pre allocating memory. It is beneficial than array
because the insertion and deletion operation is easy without reallocation. Linked list does not
give any allowance for random access.
Binary search tree:
The Binary search tree is also known as ordered binary tree. It acts like a container of
the data items that are stored in data structure. It gives the allowance for first lookup, deletion
and addition. It is also used for the implementation of the dynamic set of data items. It is a
rooted binary tree but it's internal node acts as a container of key. It has two binary sub trees
that are known as right sub tree and left sub tree. It is beneficial for sorting and searching
algorithms for traversal. By using this binary search tree, traversal becomes easy and
efficient. It follows the binary search principle.
Document Page
3COSC2140
It has no proper shape. Its shape depends on insertion and degeneration. It consumes more
time in searching. It is difficult for implementation of balanced binary search tree (BST) but
the advantage of BST is the cost of insert (), delete (), lookup () to O (logN) can be kept
always. Several times it is also called as sorted of ordered binary tress, are a specific type of
container in computer science. In this system a data structure which collets (like names,
number etc.) in memory. The users permit addition, fast lookup and the removal of items, can
be utilized for utensiling either energetic sets of items, or looking up the tables which permit
for searching an item by its key. Binary search trees retain the user keys in sorted order, so
that the operations and the lookup can be use the principal of binary search. Some variants of
the binary search tree have been learned in computer science. This article allocates primarily
with the normal type, creating references to more further types when appropriate. A rooted
binary tree, which is a binary search tree, whose internal nodes per collect a key and per have
two distinguished sub trees that can commonly denoted right and left.
The code:
#include <bits/stdc++.h>
using namespace std;
void printUniquedWords(char filename[])
// Program for Printing unique words in a file
{
fstream fs(filename); // Openning a file stream
map<string, int> mp; // Creating a map to store count of all words
string word;
while (fs >> word) // Continuously reading words while there are words to read
{

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
4COSC2140
if (!mp.count(word)) //First occurrence of word
mp.insert(make_pair(word, 1));
else
mp[word]++; //Condition
}
fs.close();
for (map<string, int> :: iterator i = mp.begin(); //Using Traverse map and printing all
words
i != mp.end(); i++)
{
if (i->second == 1)
cout << i->first << endl;
}
}
//main code
int main()
{
char filename[] = "test.txt"; //Creating a file to print the unique words
ofstream fs(filename, ios::trunc);
fs << "test guess mess test make create programming count words words words count
program";
fs.close();
printUniquedWords(filename);
return 0;
} //end of the code
Output:
Text file to sort:
Document Page
5COSC2140
Output file:
Hash Map:
Since the java was 1.2 Hash Map was a bit of mainly java’s collection. It gives the
normal implementation of the map embrasure of the java. Though t is also used in C++
programming. The program collects the data in (value, key) pairs. To entrance a value, one
must be aware its key. Hash Map uses a technique, which called hashing, for that it known as
Hash Map. Hashing is a technique of changing a huge string to a small string which represent
the same string. A little value aids in faster searches and indexing. Hash Map internally uses a
link list to collect value-key pairs earlier on explained is HashSet in further articles and
details. it is not a collection that’s means it does not give back the values and the keys in the
Document Page
6COSC2140
order, which the users have been edged into the Hash Map. It does not sort the collected
values and keys. The user must require to import super class in order or java.util. Hash Map
to use the methods and the Hash Map class.
Conclusion:
Thus it can be concluded that in this project a program for listing unique words has
been done. This project will help in future for better programming.

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7COSC2140
References:
Aaij, R., Adeva, B., Adinolfi, M., Ajaltouni, Z., Akar, S., Albrecht, J., ... & Alkhazov, G.
(2017). Observation of the doubly charmed baryon Ξ c c++. Physical review
letters, 119(11), 112001.
Kaehler, A., & Bradski, G. (2016). Learning OpenCV 3: computer vision in C++ with the
OpenCV library. " O'Reilly Media, Inc.".
Masters, T. (2018). Data Mining Algorithms in C++. Apress, New York.
Sanderson, C., & Curtin, R. (2016). Armadillo: a template-based C++ library for linear
algebra. Journal of Open Source Software, 1(2), 26.
1 out of 8
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]