Starting from:

$30

CS52-Assignment 3 Pointers, arrays, Strings, Recursion and Files Solved

Problem 1                              Matrix                                                                                                   
 

Create a 5x5 matrix of int values as shown below. Write a program that finds the minimum, maximum, and average value of all values in the matrix. Create a function for each value that is computed (max, min, avg).  Print out the results (limit the average to two decimal points!).

Matrix: [ 7, 2, 10, 3, 6], 

[ 1, 12, 2, 0, 20], 

[ 3,14,19, 5, 4], 

[ 6, 0, 17, 18, 8], 

[ 1, 13, 10, 9, 11];

Example: Min: 0, Max: 20, Avg: 8.04

Problem 2                              Dynamically Allocated Arrays                                        
 

Write a program that dynamically allocates an array based on a size determined by the user. You must declare the array as a pointer to get full credit! The program then uses a pointer to initialize each element in the array with a value that is also entered by a user. Finally, sort the array and print it to the console.

 

Example:                                              

               Enter a size: 5        

               Item 1: 3             

               Item 2: 8             

               Item 3: 5             

               Item 4: 2             

Item 5: 9

Sorted: 2, 3, 5, 8, 9
Example 2:
 

 

 
Enter a size: 3 Item 1: 15

Item 2: 3

Item 3: 7

Sorted: 3, 7, 15
           
 
                                                 

Problem 3                              First Non-repeated char                                                   
 

Write a program that prompts the user for a string (the string may consist of multiple words). Implement a function that finds and returns the first non-repeated char in the string. The program calls the function and prints out the returned char.

 

Problem 4                              Count Chars In File                                                          
 

Write a program that counts the number of upper case letters, lower case letters, digits, spaces, and any other chars in a file. The program prompts the user to enter a file name (including file path). The program then opens the file and counts each of the before mentioned categories, then prints the output.

 

Hint:

•        Use      the      library #include<fstream 

•        Create a          variable           of         type     ifstream      with     the      file            name   passed in         as        argument,       e.g.      ifstream myFile(filename);          

•        Use      getline(cin, string);  function          to        read    an            entire  line      including         whitespace                

           

Example:

         Enter a file: /Users/kalisch/Desktop/sample.txt

    File contains

    Lowercase letters: 1938

    Uppercase letters: 128

    Digits: 17

    Spaces: 35

More products