-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuffman.cpp
135 lines (114 loc) · 5.8 KB
/
huffman.cpp
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//--------------------------------------------------------------------------------------------------------------------------------
// Hassan Shahzad & Azka Khurram
// 18i-0441 & 18i-0461
// Algo-Project
// FAST NUCES
// Task2.cpp
//--------------------------------------------------------------------------------------------------------------------------------
//================================================================================================================================
// 1: This file is used to call all the functions and this class is basic interaction between the client and the system
//================================================================================================================================
#include "Queue.h"
#include "Tree.h"
#include "Encoding.h"
void displayBitArrays() {
cout << " ------------------------------- " << endl;
cout << "| Character\t|\tCode\t|" << endl;
cout << " ------------------------------- " << endl;
for (int i = 0; i < uniqueChar; i++) {
cout << "|\t" << charArray[i] << "\t|\t" << stringArray[i] << "\t|" << endl;
cout << " ------------------------------- " << endl;
}
cout << endl;
}
int main()
{
int choice = 0;
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
cout << "\t \t \t Design and Analysis of Algorithm" << endl;
cout << "\t \t \t\t End of Semester Project" << endl<<endl;
cout << "\t \t \t Task 2 (Huffman Data Compression)" << endl<<endl;
cout << "\t \t \t Hassan Shahzad & Azka Khurram" << endl;
cout << "\t \t \t\t 18i-0441 & 18i-0461" << endl;
cout << "----------------------------------------------------------------------------------------------------" << endl << endl;
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
readFile();
cout << "Characters with their respective Frequency = " << endl;
freqQueue.display();
cout << "----------------------------------------------------------------------------------------------------" << endl;
constructTree();
Bonus();
Encode();
formBitStrings();
writingASCII();
decode();
while (choice != -1)
{
cout << "Following is the list of functions that can be performed using this code :" << endl << endl;
cout << " 1: Original Size of File \n 2: No. of Unique Characters \n 3: Display Unique Characters \n 4: Display Tree 'Inorderly' \n 5: Huffman Table \n 6: 7-bit Binary Code Table \n 7: ASCII Table of 7-bit Binary Code \n 8: Display 'encoded.txt' \n 9: Display 'reconstructed.txt' \n 10: Bonus Task \n PRESS -1 TO EXIT" << endl;
cout << "Enter your choice = ";
cin >> choice;
cout << endl;
switch (choice)
{
case 1:
cout << "Total size of original.txt in bits is = " << (fileText.size() - 1) * 7 << endl;
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
break;
case 2:
cout << "Total no. of unique characters is = " << uniqueChar << endl;
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
break;
case 3:
cout << "Unique Characters are = " << endl;
for (int i = 0; i < uniqueChar; i++)
{
cout << charArray[i] << " ";
}
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
break;
break;
case 4:
cout << "Tree after all symbols are inserted:" << endl << endl;
tree.displayPostOrder();
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
break;
case 5:
cout << "Huffman Table = " << endl << endl;
displayBitArrays();
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
break;
case 6:
cout << "Displaying Seven Bits Numbers " << endl << endl;
displaysevenBit();
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
break;
case 7:
cout << "Writing ASCII values of each 7-bit Binary Code" << endl << endl;
displayASCII();
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
break;
case 8:
cout << "Displaying encoded.txt" << endl << endl;
displayEncoded();
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
break;
case 9:
cout << "Displaying reconstructed.txt " << endl << endl;
displayDecoded();
cout << endl;
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
break;
case 10:
cout << "Displaying Menu = " << endl;
displayReport();
break;
}
}
cout << endl << "----------------------------------------------------------------------------------------------------" << endl;
cout << "-------------------------------------------THE END--------------------------------------------------" << endl;
cout << "----------------------------------------------------------------------------------------------------" << endl;
}