Question

In: Electrical Engineering

this is cahce memory related c program....and not working or running properly??????? #include <iostream> #include <string>...

this is cahce memory related c program....and not working or running properly???????

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
int cash_type, block_size, cash_size,number_of_blocks=0;;
int compulsry_misses=0, capcity_misses=0, conflict_misses=0;
#define DRAM_SIZE (64*1024*1024)
unsigned int m_w = 0xABABAB55; /* must not be zero, nor 0x464fffff */
unsigned int m_z = 0x05080902; /* must not be zero, nor 0x9068ffff */
unsigned int rand_()
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}
unsigned int memGen1()
{
static unsigned int addr=0;
return (addr++)%(DRAM_SIZE);
}
unsigned int memGen2()
{
static unsigned int addr=0;
return rand_()%(128*1024);
}
unsigned int memGen3()
{
return rand_()%(DRAM_SIZE);
}
unsigned int memGen4()
{
static unsigned int addr=0;
return (addr++)%(1024);
}
unsigned int memGen5()
{
static unsigned int addr=0;
return (addr++)%(1024*64);
}
unsigned int memGen6()
{
static unsigned int addr=0;
return (addr+=256)%(DRAM_SIZE);
}
// Cache Simulator
bool cacheSim(unsigned int addr, int cash[3][100000], int type, int &block_counter, int index_addr, int tag_addr)
{
int shift_offset=log2(block_size);
bool detected=false;
bool misses_flag=true;
if (cash_type==0) // Direct Mapped ******************************************
{
if (cash[0][index_addr]==tag_addr)
{
return true;
}
else
{
cash[0][index_addr]= tag_addr;
for (int i=0; i < number_of_blocks; i++)
{
if (cash[1][i]!=1)
{ misses_flag=false;
i=number_of_blocks;}
}
//calculating misses
if (misses_flag)
capcity_misses++; // capcity miss because the cash is full
else
{
if(cash[1][index_addr]==1)
conflict_misses++;
else
{
compulsry_misses++;
}
}
cash[1][index_addr]= 1;
return 0;
}
} // end of directed mapped
///////////////////////////////////////////////////////////////////
else if (cash_type==1) // set asscoiative *************************************
{
index_addr=index_addr * type;
for (int i=0; i < type ; i++)
{
if (cash[0][index_addr+i]==tag_addr)
{
// cout <<"0x hitttttttt" << setfill('0') << setw(8) << hex << tag_addr << endl;
return 1;
}
}
for (int j=0; j < type; j++)
{
if (cash[1][index_addr+j] == -1)
{
compulsry_misses++;
cash[0][index_addr+j]=tag_addr;
cash[1][index_addr+j]=1;
return 0;
}
}
srand(time(NULL));
int x=rand()%(type);
cash[0][index_addr+x]=tag_addr;
cash[1][index_addr+x]=1;
capcity_misses++;
return 0;
}//end of set assciative
else if (cash_type==2) // fully associative **************************************
{
if (type==0) // LRU /////////
{
if (block_counter < number_of_blocks)
{
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==addr >> shift_offset)
{
detected=true;
cash[1][i]=block_counter;
block_counter--;
return detected; //hit
}
}
if (!detected)
{
compulsry_misses++;
cash[0][block_counter]=addr>>shift_offset;
cash[1][block_counter]=block_counter;
return false; //miss
}
}
else // block counter is more than block size
{
//check for existence
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==(addr >> shift_offset))
{
detected=true;
cash[1][i]=block_counter;
//block_counter--;
return detected; //hit
}
}
if (!detected)
{
int compare=0;
for (int i=1; i < number_of_blocks; i++)
{
if (cash[1][compare] > cash[1][i])
compare=i;
}
cash[0][compare]=addr >> shift_offset;
cash[1][compare]=block_counter;
capcity_misses++;
return false; //miss
}
}
} // end of LRU
else if (type==1) // LFU ///////////////
{
if (block_counter < number_of_blocks)
{
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==addr >> shift_offset)
{
detected=true;
cash[1][i]=cash[1][i]+1;
block_counter--;
return detected; //hit
}
}
if (!detected)
{
cash[0][block_counter]=addr>>shift_offset;
cash[1][block_counter]=-1;
compulsry_misses++;
return false; //miss
}
}
else // block counter is more than block size
{
//check for existence
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==(addr >> shift_offset))
{
detected=true;
cash[1][i]++;
block_counter--;
return detected; //hit
}
}
if (!detected)
{
int compare2=0;
for (int i=1; i < number_of_blocks; i++)
{
if (cash[1][compare2] >= cash[1][i])
compare2=i;
}
cash[0][compare2]=addr >> shift_offset;
cash[1][compare2]=-1;
capcity_misses++;
return false; //miss
}
}
} // end if LFU
else if (type==2)
{
if (block_counter < number_of_blocks)
{
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==addr >> shift_offset)
{
detected=true;
block_counter--;
return detected; //hit
}
}
if (!detected)
{
cash[0][block_counter]=addr>>shift_offset;
cash[1][block_counter]=block_counter;
compulsry_misses++;
return false; //miss
}
}
else // block counter is more than block size
{
//check for existence
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==(addr >> shift_offset))
{
detected=true;
//block_counter--;
return detected; //hit
}
}
if (!detected)
{
int compare=0;
for (int i=1; i < number_of_blocks; i++)
{
if (cash[1][compare] > cash[1][i])
compare=i;
}
cash[0][compare]=addr >> shift_offset;
cash[1][compare]=block_counter;
capcity_misses++;
return false; //miss
}
}
}// end of FIFO
else if (type==3)
{
if (block_counter < number_of_blocks)
{
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==addr >> shift_offset)
{
detected=true;
block_counter--;
return detected; //hit
}
}
if (!detected)
{
cash[0][block_counter]=addr>>shift_offset;
compulsry_misses++;
return false; //miss
}
}
else // block counter is more than block size
{
//check for existence
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==(addr >> shift_offset))
{
detected=true;
//block_counter--;
return detected; //hit
}
}
if (!detected)
{
srand(time(NULL));
cash[0][rand()%number_of_blocks]=addr >> shift_offset;
capcity_misses++;
return 0; //miss
}
}
}//end of RANDOM
} // end of Fully associative
return true;
}
char *msg[2] = {"Miss","Hit"};
///////////////////////////////////////////////////////////////////
int main(int argc, const char * argv[]) {
int looper=1000000, addr, flag, shift;
cout << "Please, enter 0 for Direct mapped, 1 for set associative, 2 for fully associative: " << endl;
cin >> cash_type;
cout << "Please, enter the size of the block as a Power of 2 between 4 and 128 byte :" << endl;
cin >> block_size;
cout << "Please, enter cache size: 1KB – 64KB; in steps that are power of 2: " << endl;
cin >> cash_size;
int cash[3][100000];
int block_counter=0;
int hit_counter=0;
int index_addr=0, tag_addr=0;
///////////////////////////////////////////////////////////////////
if ( cash_type==0) //Direct_mapped **************
{
number_of_blocks= (cash_size*1024)/block_size;
////////////////////
for (int i=0; i < 2; i++) // setting all the cash with -1
for (int j=0; j < number_of_blocks; j++)
cash[i][j]=-1;
//////////////////
for(int i=0; i <looper ;i++)
{
addr = memGen1();
shift= log2(block_size);
index_addr= (addr >> shift)% number_of_blocks;
shift= log2(number_of_blocks+block_size);
tag_addr= addr >>shift; // shifted the amount the offset and the index sizes
flag = cacheSim(addr, cash, 0,block_counter, index_addr, tag_addr);
index_addr=0;
tag_addr=0;
cout <<"0x" << setfill('0') << setw(8) << hex << addr <<" ("<< msg[flag] <<")\n";
if (msg[flag]=="Hit")
{
hit_counter++;
}
}
cout << "Hits " << hit_counter<<endl << "Compulsry: " << compulsry_misses <<endl<< "Capcity: " << capcity_misses <<endl<< "Conflict: " << conflict_misses << endl;
}
///////////////////////////////////////////////////////////////////
else if (cash_type==2) // Fully associative**************
{
int replacment_type;
number_of_blocks= (cash_size*1024)/block_size;
cout << "please, enter the type of replacment for the Fully Associative: LRU->0 , LFU->1, FIFO->2, RANDOM->3 :- " << endl;
cin >> replacment_type;
for (int i=0; i < 2; i++) // setting all the cash with -1
for (int j=0; j < number_of_blocks; j++)
cash[i][j]=-10;
for(int i=0; i <looper ;i++)
{
addr = memGen4();
flag = cacheSim(addr, cash, replacment_type, block_counter, index_addr, tag_addr);
// cout <<"0x" << setfill('0') << setw(8) << hex << addr <<" ("<< msg[flag] <<")\n";
if (msg[flag]=="Hit")
{
hit_counter++;
}
block_counter++;
}
cout << "Hits " << hit_counter<<endl << "Compulsry: " << compulsry_misses <<endl<< "Capcity: " << capcity_misses <<endl<< "Conflict: " << conflict_misses << endl;
} // end of fully associative main
else if (cash_type==1) // set associative
{
int number_of_ways;
cout << "please, enter the number of ways for the set associative cash: 2,4,8,16" << endl;
cin >> number_of_ways;
number_of_blocks= (cash_size*1024)/(block_size*number_of_ways);
for (int i=0; i < 3; i++) // setting all the cash with -1
for (int j=0; j < 100000; j++)
cash[i][j]=-1;
for(int i=0; i <looper ;i++)
{
addr = memGen5();
shift= log2(block_size);
index_addr= (addr >> shift)% (number_of_blocks);
shift= log2(number_of_blocks+block_size);
tag_addr= addr >>shift;
flag = cacheSim(addr, cash, number_of_ways, block_counter, index_addr, tag_addr);
// cout <<"0x" << setfill('0') << setw(8) << hex << addr <<" ("<< msg[flag] <<")\n";
index_addr=0;
tag_addr=0;
if (msg[flag]=="Hit")
{
hit_counter++;
}
block_counter++;
}
cout << "Hits " << hit_counter<<endl << "Compulsry: " << compulsry_misses <<endl<< "Capcity: " << capcity_misses <<endl<< "Conflict: " << conflict_misses << endl;
}
}

Solutions

Expert Solution

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
int cash_type, block_size, cash_size,number_of_blocks=0;;
int compulsry_misses=0, capcity_misses=0, conflict_misses=0;
#define DRAM_SIZE (64*1024*1024)
unsigned int m_w = 0xABABAB55; /* must not be zero, nor 0x464fffff */
unsigned int m_z = 0x05080902; /* must not be zero, nor 0x9068ffff */
unsigned int rand_()
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}
unsigned int memGen1()
{
static unsigned int addr=0;
return (addr++)%(DRAM_SIZE);
}
unsigned int memGen2()
{
static unsigned int addr=0;
return rand_()%(128*1024);
}
unsigned int memGen3()
{
return rand_()%(DRAM_SIZE);
}
unsigned int memGen4()
{
static unsigned int addr=0;
return (addr++)%(1024);
}
unsigned int memGen5()
{
static unsigned int addr=0;
return (addr++)%(1024*64);
}
unsigned int memGen6()
{
static unsigned int addr=0;
return (addr+=256)%(DRAM_SIZE);
}
// Cache Simulator
bool cacheSim(unsigned int addr, int cash[3][100000], int type, int &block_counter, int index_addr, int tag_addr)
{
int shift_offset=log2(block_size);
bool detected=false;
bool misses_flag=true;
if (cash_type==0) // Direct Mapped ******************************************
{
if (cash[0][index_addr]==tag_addr)
{
return true;
}
else
{
cash[0][index_addr]= tag_addr;
for (int i=0; i < number_of_blocks; i++)
{
if (cash[1][i]!=1)
{ misses_flag=false;
i=number_of_blocks;}
}
//calculating misses
if (misses_flag)
capcity_misses++; // capcity miss because the cash is full
else
{
if(cash[1][index_addr]==1)
conflict_misses++;
else
{
compulsry_misses++;
}
}
cash[1][index_addr]= 1;
return 0;
}
} // end of directed mapped
///////////////////////////////////////////////////////////////////
else if (cash_type==1) // set asscoiative *************************************
{
index_addr=index_addr * type;
for (int i=0; i < type ; i++)
{
if (cash[0][index_addr+i]==tag_addr)
{
// cout <<"0x hitttttttt" << setfill('0') << setw(8) << hex << tag_addr << endl;
return 1;
}
}
for (int j=0; j < type; j++)
{
if (cash[1][index_addr+j] == -1)
{
compulsry_misses++;
cash[0][index_addr+j]=tag_addr;
cash[1][index_addr+j]=1;
return 0;
}
}
srand(time(NULL));
int x=rand()%(type);
cash[0][index_addr+x]=tag_addr;
cash[1][index_addr+x]=1;
capcity_misses++;
return 0;
}//end of set assciative
else if (cash_type==2) // fully associative **************************************
{
if (type==0) // LRU /////////
{
if (block_counter < number_of_blocks)
{
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==addr >> shift_offset)
{
detected=true;
cash[1][i]=block_counter;
block_counter--;
return detected; //hit
}
}
if (!detected)
{
compulsry_misses++;
cash[0][block_counter]=addr>>shift_offset;
cash[1][block_counter]=block_counter;
return false; //miss
}
}
else // block counter is more than block size
{
//check for existence
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==(addr >> shift_offset))
{
detected=true;
cash[1][i]=block_counter;
//block_counter--;
return detected; //hit
}
}
if (!detected)
{
int compare=0;
for (int i=1; i < number_of_blocks; i++)
{
if (cash[1][compare] > cash[1][i])
compare=i;
}
cash[0][compare]=addr >> shift_offset;
cash[1][compare]=block_counter;
capcity_misses++;
return false; //miss
}
}
} // end of LRU
else if (type==1) // LFU ///////////////
{
if (block_counter < number_of_blocks)
{
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==addr >> shift_offset)
{
detected=true;
cash[1][i]=cash[1][i]+1;
block_counter--;
return detected; //hit
}
}
if (!detected)
{
cash[0][block_counter]=addr>>shift_offset;
cash[1][block_counter]=-1;
compulsry_misses++;
return false; //miss
}
}
else // block counter is more than block size
{
//check for existence
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==(addr >> shift_offset))
{
detected=true;
cash[1][i]++;
block_counter--;
return detected; //hit
}
}
if (!detected)
{
int compare2=0;
for (int i=1; i < number_of_blocks; i++)
{
if (cash[1][compare2] >= cash[1][i])
compare2=i;
}
cash[0][compare2]=addr >> shift_offset;
cash[1][compare2]=-1;
capcity_misses++;
return false; //miss
}
}
} // end if LFU
else if (type==2)
{
if (block_counter < number_of_blocks)
{
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==addr >> shift_offset)
{
detected=true;
block_counter--;
return detected; //hit
}
}
if (!detected)
{
cash[0][block_counter]=addr>>shift_offset;
cash[1][block_counter]=block_counter;
compulsry_misses++;
return false; //miss
}
}
else // block counter is more than block size
{
//check for existence
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==(addr >> shift_offset))
{
detected=true;
//block_counter--;
return detected; //hit
}
}
if (!detected)
{
int compare=0;
for (int i=1; i < number_of_blocks; i++)
{
if (cash[1][compare] > cash[1][i])
compare=i;
}
cash[0][compare]=addr >> shift_offset;
cash[1][compare]=block_counter;
capcity_misses++;
return false; //miss
}
}
}// end of FIFO
else if (type==3)
{
if (block_counter < number_of_blocks)
{
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==addr >> shift_offset)
{
detected=true;
block_counter--;
return detected; //hit
}
}
if (!detected)
{
cash[0][block_counter]=addr>>shift_offset;
compulsry_misses++;
return false; //miss
}
}
else // block counter is more than block size
{
//check for existence
for (int i=0; i < number_of_blocks; i++)
{
if (cash[0][i]==(addr >> shift_offset))
{
detected=true;
//block_counter--;
return detected; //hit
}
}
if (!detected)
{
srand(time(NULL));
cash[0][rand()%number_of_blocks]=addr >> shift_offset;
capcity_misses++;
return 0; //miss
}
}
}//end of RANDOM
} // end of Fully associative
return true;
}
char *msg[2] = {"Miss","Hit"};
///////////////////////////////////////////////////////////////////
int main(int argc, const char * argv[]) {
int looper=1000000, addr, flag, shift;
cout << "Please, enter 0 for Direct mapped, 1 for set associative, 2 for fully associative: " << endl;
cin >> cash_type;
cout << "Please, enter the size of the block as a Power of 2 between 4 and 128 byte :" << endl;
cin >> block_size;
cout << "Please, enter cache size: 1KB – 64KB; in steps that are power of 2: " << endl;
cin >> cash_size;
int cash[3][100000];
int block_counter=0;
int hit_counter=0;
int index_addr=0, tag_addr=0;
///////////////////////////////////////////////////////////////////
if ( cash_type==0) //Direct_mapped **************
{
number_of_blocks= (cash_size*1024)/block_size;
////////////////////
for (int i=0; i < 2; i++) // setting all the cash with -1
for (int j=0; j < number_of_blocks; j++)
cash[i][j]=-1;
//////////////////
for(int i=0; i <looper ;i++)
{
addr = memGen1();
shift= log2(block_size);
index_addr= (addr >> shift)% number_of_blocks;
shift= log2(number_of_blocks+block_size);
tag_addr= addr >>shift; // shifted the amount the offset and the index sizes
flag = cacheSim(addr, cash, 0,block_counter, index_addr, tag_addr);
index_addr=0;
tag_addr=0;
cout <<"0x" << setfill('0') << setw(8) << hex << addr <<" ("<< msg[flag] <<")\n";
if (msg[flag]=="Hit")
{
hit_counter++;
}
}
cout << "Hits " << hit_counter<<endl << "Compulsry: " << compulsry_misses <<endl<< "Capcity: " << capcity_misses <<endl<< "Conflict: " << conflict_misses << endl;
}
///////////////////////////////////////////////////////////////////
else if (cash_type==2) // Fully associative**************
{
int replacment_type;
number_of_blocks= (cash_size*1024)/block_size;
cout << "please, enter the type of replacment for the Fully Associative: LRU->0 , LFU->1, FIFO->2, RANDOM->3 :- " << endl;
cin >> replacment_type;
for (int i=0; i < 2; i++) // setting all the cash with -1
for (int j=0; j < number_of_blocks; j++)
cash[i][j]=-10;
for(int i=0; i <looper ;i++)
{
addr = memGen4();
flag = cacheSim(addr, cash, replacment_type, block_counter, index_addr, tag_addr);
// cout <<"0x" << setfill('0') << setw(8) << hex << addr <<" ("<< msg[flag] <<")\n";
if (msg[flag]=="Hit")
{
hit_counter++;
}
block_counter++;
}
cout << "Hits " << hit_counter<<endl << "Compulsry: " << compulsry_misses <<endl<< "Capcity: " << capcity_misses <<endl<< "Conflict: " << conflict_misses << endl;
} // end of fully associative main
else if (cash_type==1) // set associative
{
int number_of_ways;
cout << "please, enter the number of ways for the set associative cash: 2,4,8,16" << endl;
cin >> number_of_ways;
number_of_blocks= (cash_size*1024)/(block_size*number_of_ways);
for (int i=0; i < 3; i++) // setting all the cash with -1
for (int j=0; j < 100000; j++)
cash[i][j]=-1;
for(int i=0; i <looper ;i++)
{
addr = memGen5();
shift= log2(block_size);
index_addr= (addr >> shift)% (number_of_blocks);
shift= log2(number_of_blocks+block_size);
tag_addr= addr >>shift;
flag = cacheSim(addr, cash, number_of_ways, block_counter, index_addr, tag_addr);
// cout <<"0x" << setfill('0') << setw(8) << hex << addr <<" ("<< msg[flag] <<")\n";
index_addr=0;
tag_addr=0;
if (msg[flag]=="Hit")
{
hit_counter++;
}
block_counter++;
}
cout << "Hits " << hit_counter<<endl << "Compulsry: " << compulsry_misses <<endl<< "Capcity: " << capcity_misses <<endl<< "Conflict: " << conflict_misses << endl;
}
}


Related Solutions

Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits>...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits> #include <vector> using namespace std; // // CLASS: NODE // class Node{ public: int value = 0; // our node holds an integer Node *next = nullptr; // our node has a pointer to the next Node Node(int i){ // contructor for our Node class value = i; // store a copy of argument "i" in "value" next = nullptr; // be sure next...
modify this program to either simulate a teacher or used car salesperson. #include <iostream> #include <string>...
modify this program to either simulate a teacher or used car salesperson. #include <iostream> #include <string> using namespace std; int Menu(string a, string b, string c) { int choice =-1; cout<<" 1)"<<a<<endl; cout<<" 2)"<<b<<endl; cout<<" 3)"<<c<<endl; cout<<" 4) I don't want to talk to you!!"<<endl; cin>>choice; return choice; } int Money(int x) { int c=-1; cout<<"\n Are you that materialistic? \n"; c = Menu(" No.", " Yes.", " Can we talk about something else?"); if(c == 1|| c ==2 )...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
C++ finish the AVL Tree code: #include "AVLNode.h" #include "AVLTree.h" #include <iostream> #include <string> using namespace...
C++ finish the AVL Tree code: #include "AVLNode.h" #include "AVLTree.h" #include <iostream> #include <string> using namespace std; AVLTree::AVLTree() { root = NULL; } AVLTree::~AVLTree() { delete root; root = NULL; } // insert finds a position for x in the tree and places it there, rebalancing // as necessary. void AVLTree::insert(const string& x) { // YOUR IMPLEMENTATION GOES HERE } // remove finds x's position in the tree and removes it, rebalancing as // necessary. void AVLTree::remove(const string& x) {...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using namespace std; // M x N matrix #define M 5 #define N 5 // Naive recursive function to find the minimum cost to reach // cell (m, n) from cell (0, 0) int findMinCost(int cost[M][N], int m, int n) {    // base case    if (n == 0 || m == 0)        return INT_MAX;    // if we're at first cell...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using namespace std; int lastIndexOf(char *s, char target) { int n=strlen(s); for(int i=n-1;i>=0;i--) { if(s[i]==target) { return i; } } return -1; } void reverse(char *s) { int n=strlen(s); int i=0,j=n-1; while(i<=j) { char temp=s[i]; s[i]=s[j]; s[j]=temp; i++; j--; } return; } int replace(char *s, char target, char replacementChar) { int len=strlen(s); int total=0; for(int i=0;i<len;i++) { if(s[i]==target) { s[i]=replacementChar; total+=1; } } return total;...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h"...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h" #include"BST.cpp" using namespace std; std::vector<std::string> tokenize(char line[]) {    std::vector<std::string> tok;        std::string word = "";        for (int i = 0; i < strlen(line); i++)        {            if (i == strlen(line) - 1)            {                word += line[i];                tok.push_back(word);                return tok;       ...
For C++ Consider the following code defining classes for assets and office equipment: #include<string> #include<iostream> using...
For C++ Consider the following code defining classes for assets and office equipment: #include<string> #include<iostream> using namespace std; // class definition for asset class Asset{ protected: int value; // value of asset in cents public: Asset(int value); // constructor int get_value(); // get the value }; Asset::Asset(int val){ // implementation of constructor value=val; } int Asset::get_value(){ // implementation of get_value return value; } // abstract class for office equipment class OfficeEquipment:public Asset{ public: OfficeEquipment(int val); // constructor virtual void use_item()...
C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to...
C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to store user input bool cont = true; //implement a loop so that it will continue asking until the user provides a positive integer // the following provides ONLY part of the loop body, which you should complete { cout <<"How many words are in your message? \n"; cout <<"Enter value: "; // get user input integer here    cout <<"\nInvalid value. Please Re-enter a...
Add Bubble Sorting & Binary Search Functions to the following code (C++) #include<iostream> #include<fstream> #include<string> #include<iomanip>...
Add Bubble Sorting & Binary Search Functions to the following code (C++) #include<iostream> #include<fstream> #include<string> #include<iomanip> #include<algorithm> using namespace std; const int row = 10; const int col = 7;   ifstream name; ifstream grade; ofstream out; void readData(string stname[row], int stgrade[row][col]); void stsum(int stgrade[row][col], int total[row]); void staverage(int total[row], double average[row]); void stlettergrade(double average[row],char ltrgrade[row]); void displayData(string stname[row], int stgrade[row][col], int total[row], double staverage[row], char ltrgrade[row]); void swapltrgrade(char* xp, char* yp); int main() {    int STG[row][col] = { {0},{0}...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT