Question
Please help me for this homework problem, thanks!! Instruction( use visual studio or gcc ) 1. You are given hw03q1.c file, which contains a partially
Please help me for this homework problem, thanks!!
Instruction(use visual studio or gcc)
1. You are given hw03q1.c file, which contains a partially completed program. You are to follow the instructions contained in comments and complete the required functions. You will be writing functions for a program that does manipulation on 1-D and 2-D arrays. In one part, the program accepts four strings and an integer key as input from the user. The program will then use the integer key to encrypt the input strings (reversing the string and adding the key to each character in the string), decrypt the strings and then print the strings. In another function, one long user-input string is broken into sentences to count and print them. There is also a matrix operation of determinant which uses 2D integer array. Example output given below. Go through the C file and see the sample expected output below.
Note, when you create the Visual Studio project, the default location of project is similar to the file path shown in example figure above. For your convenience, you may change the project location while creating the project at the beginning in New Project dialog box.
hw03q1.c CODE
#include
#pragma warning(disable : 4996) // compiler directive for Visual Studio only
// Read before you start: // You are given a partially complete program. Your job is to complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify the function return types or parameters. // You can assume that all inputs are valid. Ex: If prompted for an integer, the user will input an integer.
// Global Macro Values. They are used to define the size of 2D array of characters #define NUM_STRINGS 4 #define STRING_LENGTH 50
// Forward Declarations void initializeStrings(char[NUM_STRINGS][STRING_LENGTH]); void printStrings(char[NUM_STRINGS][STRING_LENGTH]); void reverseStrings(char strings[NUM_STRINGS][STRING_LENGTH]); void encryptStrings(char[NUM_STRINGS][STRING_LENGTH], int); void decryptStrings(char[NUM_STRINGS][STRING_LENGTH], int); int splitAndPrintSentences(char s[NUM_STRINGS*STRING_LENGTH]); void inputMatrix(int matrixA[3][3]); void determinant(int matrixA[3][3]);
// Problem 1: initializeStrings // Traverse the 2D array of characters variable 'strings' (input from user in main() ) and set all characters in each // array to a null terminator so that there is a 4 row and 35 column 2D array full of null terminators. // The null terminator is represented by the character value '\0' and is used to denote the end of a string. // This may come in use later in the program to know the end of string. void initializeStrings(char strings[NUM_STRINGS][STRING_LENGTH]) {
}
// Problem 2: printStrings // Traverse the 2D character array "strings" and print each of the contained strings. // See the example outputs provided in the word document. Your output should match the example outputs. void printStrings(char strings[NUM_STRINGS][STRING_LENGTH]) {
}
// Problem 3: reverseString // Reverse each string of strings[][]. // Consider one string at a time and reverse the characters. For instance, "hi hello" should reverse to "olleh ih". void reverseStrings(char strings[NUM_STRINGS][STRING_LENGTH]) {
}
// Problem 4: encryptStrings // Traverse the 2D character array 'strings' and encrypt each string in 2 steps as follows- // 1) Reverse the string. // Hint: Use 'reverseStrings()' for this step. // 2) Then shift those ASCII characters forward by the integer value of 'key'. // If the string is "hello" and key = 2, reversing will get you "olleh" and adding key to it will result in "qnnfj" // If the value of 'key' is large, you will extend past the alphabetical characters and reach non-alphabetical characters. Thats ok.
// NOTE: DO NOT encrypt the null terminator character. Use the null terminator '\0' to find the end string. // *** NOTE: If you were unable to code for reverseStrings(), then skip that step in this function and simply shift the characters ahead by 'key'. // While decrypting in the next function, you will again have to skip the reversing part. You will get partial points in that case. void encryptStrings(char strings[NUM_STRINGS][STRING_LENGTH], int key) { } // Problem 5: decryptStrings // HINT: This should be very similiar to the encryption function defined above. // Traverse the 2D character array 'strings' and decrypt each string in 2 steps as follows- // 1) Shift those ASCII characters backward by the integer value of 'key'. // 2) Then reverse the string. // Hint: Use 'reverseStrings()' for this step. // *** NOTE: If you were unable to code for reverseStrings(), then skip that step in this function and simply shift the characters backward by 'key'. // You will get partial points in that case. void decryptStrings(char strings[NUM_STRINGS][STRING_LENGTH], int key) {
}
// Problem 6: splitAndPrintSentences // Split s[] into individual sentences and store them in str[][]. // Read s[] character by character and copy into str[][], such that sentence 1 is in str[0][], sentence 2 is in str[1][] and so on. // Print the char array str[][], so that you will print the separated sentences. Finally return the number of sentences in 'count' // Dont forget to initialize str[][] with nulls. // Hint: Sentences are separated by full-stop.
int splitAndPrintSentences(char s[NUM_STRINGS*STRING_LENGTH]) { char str[NUM_STRINGS][STRING_LENGTH]; int count = 0; // enter code below
return count;
}
// Problem 7: inputMatrix // Ask the user for each element of the 3X3 matrix and store the elements in "matrixA[][]" // Display the matrix in the following form: // matrixA = // 1 2 3 // 4 5 6 // 7 8 9 // The user may input any inetgers for matrix elements, not necessarily same as example above. void inputMatrix(int matrixA[3][3]) {
}
// Problem 8: determinant // Calculate the determinant of the 3x3 matrix "matrixA[][]" and print it. // Read about how to caclualte the determinant of 3x3 matrix. Here is a video tutorial: https://www.khanacademy.org/math/algebra-home/alg-matrices/alg-determinants-and-inverses-of-large-matrices/v/finding-the-determinant-of-a-3x3-matrix-method-2 // Since it is strictly a 3x3 matrix, you may use hardcoded indices. For eg- matrixA[0][0] to access 1st element of the matrix void determinant(int matrixA[3][3]) { int det = 0; // enter code below
printf(" Determinant of matrix = %d ", det); }
// You should study and understand how this main() works. // *** DO NOT modify it in any way *** int main() { char sentences[NUM_STRINGS*STRING_LENGTH]; char strings[NUM_STRINGS][STRING_LENGTH]; // will store four strings each with a max length of 34 int i, key, count; char input[STRING_LENGTH]; int matrixA[3][3]; // 3x3 int array for matrix printf("CSE240 HW3: 2D Character Arrays "); initializeStrings(strings); for (i = 0; i
printf(" CSE240 HW3: 2D Integer Arrays "); inputMatrix(matrixA); determinant(matrixA);
i = getchar(); // remove the character ' ' i = getchar(); // keep console open in VS return 0; }
CSE240 HW3: 2D Character Arrays, Enter string for encryption: This is ASU Enter string for encryption: CSE 240 course Enter string for encryption: Homework 3 Enter string for encryption: Tempe, Arizona Enter a key value for encryption: 3 Encrypted Strings: XVD#vitvlk hvuxrf#375#HVF 6#nurzhprk dar}luD#/hsph Decrypted Strings: This is ASU CSE 240 course Homework 3 Tempe, Arizona Enter sentences (max 4): I like Tempe. I study at ASU. I am learning C++. I like Tempe I study at ASU I am learning C++ Number of sentences= 3 CSE240 HW3: 2D Integer Arrays Enter matrix element [0][0] : 2 Enter matrix element [0(1): 4, Enter matrix element [0][2]: 5 Enter matrix element (1)[0]: 6 Enter matrix element [1][1]: 7 Enter matrix element [1] [2]: 89 Enter matrix element [2] [O]: 3 Enter matrix element [2][1]: 3 Enter matrix element [2][2]: 2, matrixA= 2 4 5 6 7 8 9 3 3 2 Determinant of matrix = 499 CSE240 HW3: 2D Character Arrays, Enter string for encryption: This is ASU Enter string for encryption: CSE 240 course Enter string for encryption: Homework 3 Enter string for encryption: Tempe, Arizona Enter a key value for encryption: 3 Encrypted Strings: XVD#vitvlk hvuxrf#375#HVF 6#nurzhprk dar}luD#/hsph Decrypted Strings: This is ASU CSE 240 course Homework 3 Tempe, Arizona Enter sentences (max 4): I like Tempe. I study at ASU. I am learning C++. I like Tempe I study at ASU I am learning C++ Number of sentences= 3 CSE240 HW3: 2D Integer Arrays Enter matrix element [0][0] : 2 Enter matrix element [0(1): 4, Enter matrix element [0][2]: 5 Enter matrix element (1)[0]: 6 Enter matrix element [1][1]: 7 Enter matrix element [1] [2]: 89 Enter matrix element [2] [O]: 3 Enter matrix element [2][1]: 3 Enter matrix element [2][2]: 2, matrixA= 2 4 5 6 7 8 9 3 3 2 Determinant of matrix = 499Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started