In: Computer Science
In the following keypad notation
Use a class and dynamic allocation of a pointer variable to enter the digit code of the following text input
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY
Use an inherited class using pointer variable to output the phone number from the following text input
1-800-COMCAST
1-800-VERIZON
1-800-BANCORP
1-800-MYKOHLS
1-800-JCPENNY
Write C++ code and pseudocode in a doc file
A computer key board has defect (like speech defect in humans) in reading for ‘p’ /’P’ as ‘f’/’F’ or vice versa and ‘n’/’N’ as ‘l’/’L’ or vice versa
Create a class with pointer variables that would correct the spelling of each word from the Input.txt print them in lexical order in an Output.txt. Write C++ code and pseudocode in a doc file
Input.txt
Pootfath
Pnof
Pullen
Fetan
Ficcadinny
Write a C++ program and algorithm for class a having two matrices one 1x5 and another 5x10 as double pointer to integer variables. Use functions to fill values of the pointer variables and output the multiplication of the two matrices. Using a pointer to integer array variable create a member function to sort the multiplied matrix to increasing order of values. Write C++ code and pseudocode in a doc file
include <iostream> //for input/output
#include <fstream> //for ifstream.
#include <string> //for string functions. using namespace std; class Week
//class named Week
{
private: string weekday[7];
//array of strings to store the day. int i;
//to indicate how many strings read from file. public: void readDays
(string file_name)
{
//
reads days from file passed in.
ifstream read(file_name.c_str());
//input stream is created.
if(read==NULL)
{
//if file fails to open then cout
<
<"file failed to open";
//this message is printed and. return;
//returns, further execution of this function is stopped.
}
i=0;
//assigns 0 to i. while(read>>weekday[i])
{
//reads day names from file to name array of strings.
i++;
//increments i value.
}
read.close();
//closes the input stream.
}
//digit function returns corresponding digit for the character passed in.
int digit
(char ch)
{
if(ch=='A'||ch=='B'||ch=='C') return 2;
else if(ch=='D'||ch=='E'||ch=='F') return 3;
else if(ch=='G'||ch=='H'||ch=='I') return 4;
else if(ch=='J'||ch=='K'||ch=='L') return 5;
else if(ch=='M'||ch=='N'||ch=='O') return 6;
else if(ch=='P'||ch=='Q'||ch=='R'||ch=='S') return 7;
else if(ch=='T'||ch=='U'||ch=='V') return 8;
else if(ch=='W'||ch=='X'||ch=='Y'||ch=='Z') return 9;
} //writeDays function takes file name and writes into file.
void writeDays(string file_name)
{
ofstream write(file_name.c_str());
//ofstream is created for the file passed in.
if(write==NULL)
{
//if write is null then cout<<
"file failed to open";
//this message is printed and. return;//no further exectuion is done.
}
for(int j=0;j<i;j++)
//iterates through the string values read from file.
{ int len = weekday[j].length();
//len stores length of the corresponding string.
for
(int k=0;k<len
;k++)//
loops through the stringacter into the file.
}
write<<"\n";
//writes newline into file.
}
write.close();
//outputstream is closed.
}
}
; //main function. int main()
{ Week w;//object for class Week is declared.
Week *ptr = &w;
//pointer for class Week is created and assigned address of object n.
ptr->readDays("weekdays.txt");
//calls readDays function by passing file name.
ptr->writeDays("digit_weekdays.txt");
//calls printNames function. return 0;
//terminate program by returning 0. }
//digit_weekdays.txt generated
//weekdays.txt input file given
Input.txt file
Output.txt
C++ Program
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class Matrix {
public:
int **mat;
int r, c;
Matrix(int row, int col) {
r = row;
c = col;
mat = new int*[r];
for(int i=0; i<r; i++) {
mat[i] = new int[c];
}
}
void setMatrix(int **m) {
mat = m;
}
void input() {
for(int i=0; i<r; i++) {
for(int j=0; j<c; j++) {
mat[i][j] = rand() % 10;
}
}
}
Matrix multiply(Matrix b) {
int **mult;
mult = new int*[r];
for(int i=0; i<r; i++) {
mult[i] = new int[b.c];
}
for(int i = 0; i < r; ++i){
for(int j = 0; j < b.c; ++j) {
mult[i][j] = 0;
}
}
// Multiplying matrix a and b and storing in array mult.
for(int i = 0; i < r; ++i){
for(int j = 0; j < b.c; ++j) {
for(int k = 0; k < c; ++k) {
mult[i][j] += mat[i][k] * b.mat[k][j];
}
}
}
Matrix product(r, b.c);
product.setMatrix(mult);
return product;
}
void sortMatrix() {
int *arr = new int[r*c];
int k=0;
for(int i = 0; i < r; ++i){
for(int j = 0; j < c; ++j) {
arr[k ++] = mat[i][j];
}
}
int count1,count2,swap;
for(count1=0;count1<r*c - 1;count1++) {
for(count2=0;count2<r*c - count1 - 1;count2++) {
if(*(arr+count2) < *(arr+count2+1)) {
swap=*(arr+count2);
*(arr+count2)=*(arr+count2+1);
*(arr+count2+1)=swap;
}
}
}
for(count1=0;count1<r*c;count1++) {
cout<<*(arr+count1)<<" ";
}
}
void display() {
for(int i=0; i<r; i++) {
for(int j=0; j<c; j++) {
cout << mat[i][j] << " ";
}
cout << endl;
}
}
};
int main() {
srand(time(NULL));
Matrix mat1(1, 5), mat2(5, 10);
mat1.input();
mat2.input();
cout << "Matrix 1 : " << endl;
mat1.display();
cout << endl << "Matrix 2 : " << endl;
mat2.display();
Matrix product = mat1.multiply(mat2);
cout << endl << "Sorted Matrix product : " <<
endl;
product.sortMatrix();
return 0;
}
Output
THANK YOU!; PLEASE VOTE