Enhance And Optimize Your Website SEO for $25

With some of my professional SEO tricks, I will make your site being a strong competitor in Search Engines. I can promise you better S.E.O score,improvement and higher rank in search engine in the future. I use latest methods recommended by Google.I will cover:Keywords Research and PlacementAdd Meta Tags ,Meta Description,Meta LanguageSet up G. Webmaster ToolSet up G. AnalyticsSet up G. Tag ManagerCreation of Robots.txtSitemap Creation and submit to search engines.H1, H2 ,H3, TagsCanonical URLConnect with Social Media Remove Broken LinksSEO Friendly URLImage Alt tag,images optimizationSite Navigation IssuesAdvice you for further optimizations After fixing all these SEO centric issues, your website will gain a lot of traffic and increase its visibility in organic search results of search engine for targeted keywords. I will do SEO for every kind of website including platforms like WordPress, Wix, SquareSpace, Shopify, Weebly, Magento, Joomla etc even HTML or PHP website or web application. I guarantee 100% Money Back. It is necessary your platform login details and a gmail account associated to your website to setup google webmaster tools and google analytics.

by: AffaanNasir
Created: —
Category: Onsite SEO & Research
Viewed: 165


Could I have some advice and be shown how to optimize some parts of my InventorySystem’s codebase?

I’m here looking for a review over my current code-base.

Please:

  • Ignore using namespace std; this is for educational purposes mostly so the usage of using namespace std; does not matter for this codebase as it’s a project thrown together for educational purposes.

  • Look at some parts of my code which I will point out below and if possible, look at the rest giving me feedback and telling me how to possibly improve/showing me.

In my InventorySystem, I have code which reads into a text-file that’s structured like so:

{ 123, A piece of cheese., 10.19, 4, }  { 321, A country flag, 10.00, 1, } 

Specifically, it has Packet.h’s structure which you can see below.

This code

string line, line2, line3, line4;         int num1;         double num2;         int num3;         while (getline(inFile, line)) {             getline(inFile, line);             line = line.substr(0, line.size() - 1);             num1 = stoi(line);             getline(inFile, line2);             line2 = line2.substr(0, line2.size() - 1);             getline(inFile, line3);             line3 = line3.substr(0, line3.size() - 1);             num2 = stod(line3);             getline(inFile, line4);             line4 = line4.substr(0, line4.size() - 1);             num3 = stoi(line4);             Packet importPacket(num1, line2, num2, num3);             inventorySystem.insert(importPacket);             getline(inFile, line);             getline(inFile, line);         }         inFile.close(); 

in the beginning of int main() in Inventory.cpp is supposed to read into it section by section. But looking at the code, as you can see it seems very clunky. Do you have any suggestions for improving it? Note that it tosses out the “,” seen at the end of every attribute so that it can read the id, description, price, partCount of Packet.h.

There’s also this part

else if (choice == 'a') {                 cout << "Archiving all the information." << endl;                 Sleep(1000);                 cout << "Archiving all the information.." << endl;                 Sleep(1000);                 cout << "Archiving all the information..." << endl;                 vector <Packet*> getPackets = inventorySystem.extract();                  bOutFile.open("C:\...Put_Your_Path_Here.dat", ios::out | ios::binary);                 for (int i = 0; i < getPackets.size(); ++i) {                     bOutFile.write((char*)&getPackets[i], sizeof(getPackets[i]));                 }                 bOutFile.close();             } 

for archiving to binary .dat purposes where I use the extract function on the binary search tree to grab all of its contents and put them into a vector for archiving into .dat purposes. I’m not sure if this is a good way of doing so. Could it be improved? I want to extract still so that I don’t have to write more code if possible. This code also uses pretty much the preorder traversal in order to extract contents of BST. It’s pretty repetitive. This code can be found in int main() at the if…choice “a.” Here’s how it executes from BST.cpp:

vector <Packet*> BST::extract() const {     vector <Packet*> result;      if (root != nullptr) {         extract(root, result);     }      return result; }  void BST::extract(const Node *p, vector <Packet*> &result) const {     if (p != nullptr) {         result.push_back(p->data);         extract(p->llink, result);         extract(p->rlink, result);     } } 

It’s recursive. That’s all. But if you can look at other parts of the codebase that’d be really great too!

This part for reference purposes:


Inventory.cpp:

#include <iostream> #include <string> #include <fstream> #include "windows.h"   #include "BST.h" #include "Packet.h"  using namespace std;  /*     PURPOSE: Process inventory information for a parts warehouse.     1. Read from txt. file used for storing information between sessions.         *Txtfile can be empty.     2. Pop up 5 choices in main menu: enter a new part to system, find and print data for a part when given the part ID number,     and find and modify data for a part when given the part ID number, copy all information to a binary archive file, and quit. */  int main() {     BST inventorySystem;     ifstream inFile("C:\...Put_Your_Path_Here.txt");     ofstream outFile;     fstream bOutFile;      if (!inFile) {         cerr << "ERROR: Unable to open the text file." << endl;     }     else {         string line, line2, line3, line4;         int num1;         double num2;         int num3;         while (getline(inFile, line)) {             getline(inFile, line);             line = line.substr(0, line.size() - 1);             num1 = stoi(line);             getline(inFile, line2);             line2 = line2.substr(0, line2.size() - 1);             getline(inFile, line3);             line3 = line3.substr(0, line3.size() - 1);             num2 = stod(line3);             getline(inFile, line4);             line4 = line4.substr(0, line4.size() - 1);             num3 = stoi(line4);             Packet importPacket(num1, line2, num2, num3);             inventorySystem.insert(importPacket);             getline(inFile, line);             getline(inFile, line);         }         inFile.close();           char choice = 'z';          while (choice != 'q') {             cout << "-----------------------------------------------------" << endl;             cout << "Program successfully loaded..." << endl;             cout << "Welcome to the main menu..." << endl;             cout << "-----------------------------------------------------" << endl;             cout << "N: Enter new part into the system >>" << endl;             cout << "F: Find a particular part >>" << endl;             cout << "A: Archive the information >>" << endl;             cout << "Q: Quit >>" << endl;             cout << "Input your choice: ";             cin >> choice;             choice = tolower(choice);              if (choice == 'n') {                 cout << "Enter the new part's I.D.: ";                 int partId = -1;                 cin >> partId;                 cin.ignore();; // Flushes the input stream and removes the new line(s) at the end of the stream for the upcoming getline.                 cout << "Enter a short description for this new part: ";                 string description = "";                 getline(cin, description);                 cout << "Enter the price of this new part: $  ";                 double price = 0.00;                 cin >> price;                 cout << "Enter how many parts the warehouse currently has: ";                  int partCount = 0;                 cin >> partCount;                  if (partId >= 0 && price >= 0 && partCount >= 0) {                     Packet packet(partId, description, price, partCount);                     inventorySystem.insert(packet);                     cout << "Attempted to enter the part into the SYSTEM." << endl;                 }                 else {                     cout << "One or more inputs are invalid. You will be prompted back to the menu. Please enter a valid input!" << endl;                     cout << "Usage: PartID should be greater than or equal to 0, price should be similar, and vice versa!" << endl;                 }             }             else if (choice == 'f') {                 cout << "Enter the part I.D. that you want to search the database for: ";                 int partId = -1;                 cin >> partId;                 Packet* getPacket = inventorySystem.search(partId);                  if (getPacket != nullptr) {                     cout << "{" << endl;                     cout << "I.D.: " << getPacket->getPartId() << endl;                     cout << "Description: " << getPacket->getDescription() << endl;                     cout << "Price: " << getPacket->getPrice() << endl;                     cout << "Part Count: " << getPacket->getPartCount() << endl;                     cout << "}" << endl;                 }                 else {                     cout << "ERROR: System could not find the following I.D. as part of the inventory system." << endl;                 }             }             else if (choice == 'a') {                 cout << "Archiving all the information." << endl;                 Sleep(1000);                 cout << "Archiving all the information.." << endl;                 Sleep(1000);                 cout << "Archiving all the information..." << endl;                 vector <Packet*> getPackets = inventorySystem.extract();                  bOutFile.open("C:\...Put_Your_Path_Here.dat", ios::out | ios::binary);                 for (int i = 0; i < getPackets.size(); ++i) {                     bOutFile.write((char*)&getPackets[i], sizeof(getPackets[i]));                 }                 bOutFile.close();             }         }          vector <Packet*> getPackets = inventorySystem.extract();          outFile.open("C:\...Put_Your_Path_Here.txt");         for (int i = 0; i < getPackets.size(); ++i) {             outFile << "{" << endl;             outFile << getPackets[i]->getPartId() << "," << endl;             outFile << getPackets[i]->getDescription() << "," << endl;             outFile << getPackets[i]->getPartCount() << "," << endl;             outFile << getPackets[i]->getPrice() << "," << endl;             outFile << "}" << endl << endl;         }         outFile.close();     }     system("pause"); } 

BST.h:

#pragma once  #include "Packet.h" #include <vector>  using namespace std;  class BST {     struct Node {         Node() : rlink(nullptr), llink(nullptr) {};         ~Node() {};          Packet *data;         Node *rlink, *llink;     }; public:     BST();     void insert(Packet &p);     void insert(Node *&p, Node *newNode);     Packet* search(int id);     vector <Packet*> extract() const;     void preorderTraversal() const;     void destroyTree();     ~BST(); private:     Node * root;     void destroyTree(Node *&p);     Packet* search(const Node *p, int id);     void extract(const Node *p, vector <Packet*> &result) const;     void preorderTraversal(const Node *p) const; }; 

BST.cpp:

#include "BST.h" #include <iostream>  BST::BST() : root(nullptr) {}  void BST::insert(Packet &p) {     if (search(p.getPartId()) == nullptr) {         Node *newNode = new Node;         newNode->data = new Packet(p);         insert(root, newNode);     }     else {         cout << "Insertion failed because such packet has already been found to exist." << endl;     } }  void BST::insert(Node *&p, Node *newNode) {     if (p == nullptr) {         p = newNode;     }     else if (p->data->getPartId() > newNode->data->getPartId()) {         insert(p->llink, newNode);     }     else {         insert(p->rlink, newNode);     } }  Packet* BST::search(int id) {     return search(root, id); }  Packet* BST::search(const Node *p, int id) {     if (p == nullptr) {         return nullptr;     }     else if (p->data->getPartId() == id) {         return p->data;     }     else if (p->data->getPartId() < id) {         return search(p->rlink, id);     }      return search(root->llink, id); }  vector <Packet*> BST::extract() const {     vector <Packet*> result;      if (root != nullptr) {         extract(root, result);     }      return result; }  void BST::extract(const Node *p, vector <Packet*> &result) const {     if (p != nullptr) {         result.push_back(p->data);         extract(p->llink, result);         extract(p->rlink, result);     } }  void BST::preorderTraversal() const {     if (root == nullptr) {         cerr << "There is no tree.";     }     else {         preorderTraversal(root);     } }  void BST::preorderTraversal(const Node *p) const {     if (p != nullptr) {         cout << p->data->getPartId() << " ";         preorderTraversal(p->llink);         preorderTraversal(p->rlink);     } }  void BST::destroyTree(Node *&p) {     if (p != nullptr) {         destroyTree(p->llink);         destroyTree(p->rlink);         delete p;         p = nullptr;     } }  void BST::destroyTree() {     destroyTree(root); }  BST::~BST() {     destroyTree(root); } 

Packet.h:

#pragma once #include <string>  using namespace std;  class Packet {     public:         Packet(int partId, string description, double price, int partCount) :              partId(partId), description(description), price(price), partCount(partCount) {}         int getPartId() const {return partId;}         string getDescription() const {return description;}         double getPrice() const {return price;}         int getPartCount() const {return partCount;}      private:         int partId;         string description;         double price;         int partCount; }; 

Does the gcc optimize out local arrays the same way it would optimize out a local variable?

If I write this code in a function:

void func(void) {     int x = 0;     int y = 3724832+x; } 

It would (probably) optimize the variable y out because it isn’t being used. Even if I’m wrong about this specific case, the point I’m making is that the compiler has the ability to optimize out variables.

My question is does it also do this with local arrays?

Example:

void func(void) {     uint8_t tempBuffer[2] = {0x00, 0x01};     sendBufferOverUSB(tempBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

Does the compiler then optimize this array out? Or does it keep this array in memory forever? Or is that even what optimization means? I know that arrays are created at compile time, so I’m trying to figure out if I should be using arrays in the way I’ve just used them or if I should make an array for every .c file as a buffer and simply use that whenever I need to store some bytes for transmission. Like this:

//example.c #include "example.h" #define MAX_EXAMPLE_BUFFER_SIZE 256 static uint8_t localBuffer[MAX_EXAMPLE_BUFFER_SIZE]; void func(void) {     // using buffer      localBuffer[0] = 0x00;     localBuffer[1] = 0x01;     sendBufferOverUSB(localBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

I am going to have a bunch of functions which need to convert from Little Endian variables into Big Endian formatted bytes so i essentially need some buffer to move these bytes into, and I just didn’t know if making an array of the size needed was better than using a buffer for that .c file.

Does the gcc optimize out local arrays the same way it would optimize out a local variable?

If I write this code in a function:

void func(void) {     int x = 0;     int y = 3724832+x; } 

It would (probably) optimize the variable y out because it isn’t being used. Even if I’m wrong about this specific case, the point I’m making is that the compiler has the ability to optimize out variables.

My question is does it also do this with local arrays?

Example:

void func(void) {     uint8_t tempBuffer[2] = {0x00, 0x01};     sendBufferOverUSB(tempBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

Does the compiler then optimize this array out? Or does it keep this array in memory forever? Or is that even what optimization means? I know that arrays are created at compile time, so I’m trying to figure out if I should be using arrays in the way I’ve just used them or if I should make an array for every .c file as a buffer and simply use that whenever I need to store some bytes for transmission. Like this:

//example.c #include "example.h" #define MAX_EXAMPLE_BUFFER_SIZE 256 static uint8_t localBuffer[MAX_EXAMPLE_BUFFER_SIZE]; void func(void) {     // using buffer      localBuffer[0] = 0x00;     localBuffer[1] = 0x01;     sendBufferOverUSB(localBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

I am going to have a bunch of functions which need to convert from Little Endian variables into Big Endian formatted bytes so i essentially need some buffer to move these bytes into, and I just didn’t know if making an array of the size needed was better than using a buffer for that .c file.

Does the gcc optimize out local arrays the same way it would optimize out a local variable?

If I write this code in a function:

void func(void) {     int x = 0;     int y = 3724832+x; } 

It would (probably) optimize the variable y out because it isn’t being used. Even if I’m wrong about this specific case, the point I’m making is that the compiler has the ability to optimize out variables.

My question is does it also do this with local arrays?

Example:

void func(void) {     uint8_t tempBuffer[2] = {0x00, 0x01};     sendBufferOverUSB(tempBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

Does the compiler then optimize this array out? Or does it keep this array in memory forever? Or is that even what optimization means? I know that arrays are created at compile time, so I’m trying to figure out if I should be using arrays in the way I’ve just used them or if I should make an array for every .c file as a buffer and simply use that whenever I need to store some bytes for transmission. Like this:

//example.c #include "example.h" #define MAX_EXAMPLE_BUFFER_SIZE 256 static uint8_t localBuffer[MAX_EXAMPLE_BUFFER_SIZE]; void func(void) {     // using buffer      localBuffer[0] = 0x00;     localBuffer[1] = 0x01;     sendBufferOverUSB(localBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

I am going to have a bunch of functions which need to convert from Little Endian variables into Big Endian formatted bytes so i essentially need some buffer to move these bytes into, and I just didn’t know if making an array of the size needed was better than using a buffer for that .c file.

Does the gcc optimize out local arrays the same way it would optimize out a local variable?

If I write this code in a function:

void func(void) {     int x = 0;     int y = 3724832+x; } 

It would (probably) optimize the variable y out because it isn’t being used. Even if I’m wrong about this specific case, the point I’m making is that the compiler has the ability to optimize out variables.

My question is does it also do this with local arrays?

Example:

void func(void) {     uint8_t tempBuffer[2] = {0x00, 0x01};     sendBufferOverUSB(tempBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

Does the compiler then optimize this array out? Or does it keep this array in memory forever? Or is that even what optimization means? I know that arrays are created at compile time, so I’m trying to figure out if I should be using arrays in the way I’ve just used them or if I should make an array for every .c file as a buffer and simply use that whenever I need to store some bytes for transmission. Like this:

//example.c #include "example.h" #define MAX_EXAMPLE_BUFFER_SIZE 256 static uint8_t localBuffer[MAX_EXAMPLE_BUFFER_SIZE]; void func(void) {     // using buffer      localBuffer[0] = 0x00;     localBuffer[1] = 0x01;     sendBufferOverUSB(localBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

I am going to have a bunch of functions which need to convert from Little Endian variables into Big Endian formatted bytes so i essentially need some buffer to move these bytes into, and I just didn’t know if making an array of the size needed was better than using a buffer for that .c file.

Does the gcc optimize out local arrays the same way it would optimize out a local variable?

If I write this code in a function:

void func(void) {     int x = 0;     int y = 3724832+x; } 

It would (probably) optimize the variable y out because it isn’t being used. Even if I’m wrong about this specific case, the point I’m making is that the compiler has the ability to optimize out variables.

My question is does it also do this with local arrays?

Example:

void func(void) {     uint8_t tempBuffer[2] = {0x00, 0x01};     sendBufferOverUSB(tempBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

Does the compiler then optimize this array out? Or does it keep this array in memory forever? Or is that even what optimization means? I know that arrays are created at compile time, so I’m trying to figure out if I should be using arrays in the way I’ve just used them or if I should make an array for every .c file as a buffer and simply use that whenever I need to store some bytes for transmission. Like this:

//example.c #include "example.h" #define MAX_EXAMPLE_BUFFER_SIZE 256 static uint8_t localBuffer[MAX_EXAMPLE_BUFFER_SIZE]; void func(void) {     // using buffer      localBuffer[0] = 0x00;     localBuffer[1] = 0x01;     sendBufferOverUSB(localBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

I am going to have a bunch of functions which need to convert from Little Endian variables into Big Endian formatted bytes so i essentially need some buffer to move these bytes into, and I just didn’t know if making an array of the size needed was better than using a buffer for that .c file.

Does the gcc optimize out local arrays the same way it would optimize out a local variable?

If I write this code in a function:

void func(void) {     int x = 0;     int y = 3724832+x; } 

It would (probably) optimize the variable y out because it isn’t being used. Even if I’m wrong about this specific case, the point I’m making is that the compiler has the ability to optimize out variables.

My question is does it also do this with local arrays?

Example:

void func(void) {     uint8_t tempBuffer[2] = {0x00, 0x01};     sendBufferOverUSB(tempBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

Does the compiler then optimize this array out? Or does it keep this array in memory forever? Or is that even what optimization means? I know that arrays are created at compile time, so I’m trying to figure out if I should be using arrays in the way I’ve just used them or if I should make an array for every .c file as a buffer and simply use that whenever I need to store some bytes for transmission. Like this:

//example.c #include "example.h" #define MAX_EXAMPLE_BUFFER_SIZE 256 static uint8_t localBuffer[MAX_EXAMPLE_BUFFER_SIZE]; void func(void) {     // using buffer      localBuffer[0] = 0x00;     localBuffer[1] = 0x01;     sendBufferOverUSB(localBuffer, 2); //sendBufferOverUSB(uint8_t* arr, int sizeArr); } 

I am going to have a bunch of functions which need to convert from Little Endian variables into Big Endian formatted bytes so i essentially need some buffer to move these bytes into, and I just didn’t know if making an array of the size needed was better than using a buffer for that .c file.