Starting from:

$25

CSE1242 -  COMPUTER PROGRAMMING II  - Programming Assignment  2   - Solved

1.      Write a function that will take one integer pointer, *number, and an integer N. Then reverse number's last N digits. 

 

•      The function header must be as the following: 

 

void reverseN(int *number, int N) 

•      You should take input numbers from the user in main function and then invoke the function reverseN with appropriate parameters.  

•      The main function should print the result, as the updated value of the number. 

 

Sample Runs: 

Run 1:

176 2 

167
 

Run 2:

63712 3 

63217
 

Run 2:

32145 5 

54123
 

Run 2:

345 5 

N must be less than 4!
 

 

•      You should perform appropriate error checking whether the N is greater than the number of digits of number.  

 

 

2.      In this question, you will write a program to print the letters W, X, Y and Z using the character of ‘*’ with the given size. Make sure your program conforms to the following requirements: 

 

•      Accept the size of the letter (in the number of lines) from the user. This number should be an odd number greater than or equal to 5. If the value entered is invalid, tell the user so, and ask for another one. Repeat until you get a valid size.  

 

•      Accept the letter to be printed from the user. If the letter is W, X, Y or Z, go to the next step. If not, tell the user that the letter is invalid, and ask for another one. Repeat until you get a valid letter.  

 

•      Print the letter by using ‘*’ character with the given size. The sample run gives examples for each letter.  

 

•      Repeat the entire process if the user indicates they wish to continue.  

 

 

 

Example: 

 

 

Welcome to the letter printer. 

Enter the size: 3 

Invalid size. Enter the size again: -4 

Invalid size. Enter the size again: 7 

Enter the letter: C 

Invalid letter: Enter the letter again: # 

Invalid letter: Enter the letter again: X  

*        * 

*        * 

*        *    * 

*        * 

*        * 

*        * 

 

 

 

 

 

Would you like to continue? (Y or N): Y 

Enter the size: 8 

Invalid size. Enter the size again: 11 

Enter the letter: Z 

 

*********** 

          *   

         *     

        *       

       *         

      * 

     * 

    * 

   * 

  * 

 * 

*********** 

 

 

 

 

 

Would you like to continue? (Y or N): Y 

Enter the size: 9 

Enter the letter: W 

 

*                                                          *                              *  

*                                                          *  *                          * 

*                                                          *      *                      *     

*                                                          *          *                  *       

*                                                          *              *              *         

*                                                          *                  *          *            

*                                                          *                      *      *             

*                                                          *                          *  *              

*                                                          *                      

 

 

 

 

 

Would you like to continue? (Y or N): Y 

Enter the size: 5 

Enter the letter: Y 

 

*                                                          *           

*                                                          * 

    * 

    * 

    *  

 

 

 

 

 

Would you like to continue? (Y or N): N 

Goodbye :) 

More products