Question

In: Computer Science

In the following keypad notation Use a class and dynamic allocation of a pointer variable to...

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

Solutions

Expert Solution

#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


Related Solutions

In the following keypad notation Use a class and dynamic allocation of a pointer variable to...
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...
Using C++ Use dynamic allocation and functions (using pointer variables only) to read the names from...
Using C++ Use dynamic allocation and functions (using pointer variables only) to read the names from the .txt file and sort the names in lexical order Grumpy Dopey Doc Happy Bashful Sneezy Sleepy
In C++ Create a dynamic array of 100 integer values named myNums. Use a pointer variable...
In C++ Create a dynamic array of 100 integer values named myNums. Use a pointer variable (like ptr) which points to this array. Use this pointer variable to initialize the myNums array from 2 to 200 and then display the array elements. Delete the dynamic array myNums at the end. You just need to write part of the program.
When it comes to dynamic memory allocation and delete[] pointer, what does it mean to say...
When it comes to dynamic memory allocation and delete[] pointer, what does it mean to say that, CRT detected that the application wrote to memory after end of heap buffer? I tried to duplicate the error by deleting the pointer address twice and it didn't produce the same error code so that's not it. What might cause this problem?
Purpose Review and reinforcement of pointers, dynamic memory allocation, pointer arithmetic, passing pointers to a function,...
Purpose Review and reinforcement of pointers, dynamic memory allocation, pointer arithmetic, passing pointers to a function, returning a pointer by a function, dangling pointer, and memory deallocation, pointer initialization, and struct data type. Project description In this project, you will create a database of employees of an organization while meeting the requirements described below. Your program MUST NOT interact with the user to receive inputs, so that the instructor and/or the teaching assistant can save a big time in testing...
Write a function to concatenate two strings using pointer notation
Write a function to concatenate two strings using pointer notation
In the assignment you will use the vector class tomanage a dynamic array.After completing this assignmentyou...
In the assignment you will use the vector class tomanage a dynamic array.After completing this assignmentyou will be able to • use thevector classto implement programs; • using iteratorsto morethrough a vector; • use pointers to a vector; • use member functions of thevector class. Assignment Description: Call your driver "vector_test_driver.cpp", your classdeclaration file “vlist.h” and your class implementation file "vlist.cpp". Define the following behavior for vlist 1. Implement a default constructor. Include the followingmessage, "Default Constructor Invoked" every time...
A) As a portfolio manager, you apply dynamic allocation. Your 62-year old client with the following...
A) As a portfolio manager, you apply dynamic allocation. Your 62-year old client with the following portfolio information needs your help to split her money into equity and bond positions. How much does she need to invest in each of these asset classes? Please show your work. m = 1.5 Portfolio current value = $1,500,000 Floor: $500,000 B) What are your thoughts on your final answer in part (A)? Do you think this asset allocation is appropriate for your client?...
Write a C++ program (using pointers and dynamic memory allocation only) to implement the following functions...
Write a C++ program (using pointers and dynamic memory allocation only) to implement the following functions and call it from the main function. (1)Write a function whose signature looks like (char*, char) which returns true if the 1st parameter cstring contains the 2nd parameter char, or false otherwise. (2)Create an array of Planets. Populate the array and print the contents of the array using the pointer notation instead of the subscripts.
Modify the following code to use ONLY pointer arithmetic (no array expressions) and no for loops...
Modify the following code to use ONLY pointer arithmetic (no array expressions) and no for loops to do the same thing this code does. Be sure that you understand how the code works and how the pointer arithmetic relates to the array expression form. Provide liberal comments to explain what your pointer arithmetic is computing. #include <stdlib.h> #include <stdio.h> int main(int argc, char **argv) { int arg_count = 0; for (arg_count = 0; arg_count < argc; arg_count++) printf("%s\n", argv[arg_count]); }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT