Management Information System
Autor: fahadrafi • June 1, 2015 • Coursework • 1,345 Words (6 Pages) • 1,365 Views
Page 1 of 6
Programming Fundamentals Assignment 3
Instructions
- Indent your code properly & follow variable name giving conventions.
- There will be no makeup of this assignment.
- Use best coding practices.
- Cheating and sharing is strictly prohibited.
- Student Copying Assignment / Lab / Quiz will be grade 100% negative marks.
- Student Copying Assignment / Lab / Quiz, two or more times will be dropped from lab/course.
- No Excuse will be entertained when Submission timing is over.
- Submit is submission folder till 1:00 pm Thursday, September 11, 2014.
- Follow the submission details told in class.
Basic Practice Problems:
- All examples and exercises from chapter 6 and 7.
- Write a C++ program to reverse the element of an integer 1-D array.
- Write a C++ program to swap first and last element, then second and second last element and so on of an integer 1-d user defined array.
- Suppose A, B, C are arrays of integers of size M, N, and M + N respectively. The numbers in array A appear in ascending order while the numbers in array B appear in descending order. Write a program to produce third array C by merging arrays A and B in ascending order.
- Write a function called zero_small() that has two integer arguments being passed by reference and sets the smaller of the two numbers to 0. Write the main program to access the function.
- Given two arrays of integers A and B of sizes M and N respectively. Write a function named MIX () with four arguments, which will produce a third array named C. such that the following sequence is followed.
All even numbers of A from left to right are copied into C from left to right.
All odd numbers of A from left to right are copied into C from right to left.
All even numbers of B from left to right are copied into C from left to right.
All old numbers of B from left to right are copied into C from right to left.
A, B and C are passed as arguments to MIX (). e.g., A is {3, 2, 1, 7, 6, 3} and B is {9, 3, 5, 6, 2, 8, 10} the resultant array C is {2, 6, 6, 2, 8, 10, 5, 3, 9, 3, 7, 1, 3} - Write a program that lets the user perform arithmetic operations on two numbers. Your program must be menu driven, allowing the user to select the operation (+, -, *, or /) and input the numbers. Furthermore, your program must consist of following functions:
1. Function showChoice(): This function shows the options to the user and explains how to enter data.
2. Function add: This function accepts two number as arguments and returns sum.
3. Function subtract: This function accepts two number as arguments and returns their difference.
4. Function multiply: This function accepts two number as arguments and returns product.
5. Function divide: This function accepts two number as arguments and returns quotient. - You have to write a program in which you have to declare an array of SIZE , any constant value.
- Call a function initArray(int []) and pass the array in it. The function should initialize all the array elements to user given values. Function returns nothing.
- Now call another function doubleArray(int []) which receives same array as that of initialized array and returns the square of each element of the original array.
Example :
Arr [SIZE]={1,2,3,4,5,6,7,8,9,10};\\if SIZE was 10, input was like this
Returned array will have 1,4,9,16,25,36,49,64,81,100.
- Write separate function to perform following tasks with in the program for character array. You can define constant size as 500. Take input in array and
- Find the length of a user given array
- Concatenating two user given character arrays
- Replace a user given word (a character array) from a user given array.
- Write a function convertbinary(int a) that takes one parameter and convert the received number in binary, and display the binary value. Test with main().
- Do the task discussed in end of the class for row and column major traversal of 2d and 1d arrays.
Tasks to submit as an assignment
- You have to write a function that takes 3 Parameters as their default values “4”. The function should return the L.C.M of all the arguments passed. You will call the function in main() like
LCM(3);
LCM(4,4);
LCM(1,2,4);
LCM();
Or it can be called after taking values from user to pass as parameters.
- Paper, Scissor and Rock is a very famous game. Two players choose any of the given choice.
- If Player 1 chooses “Paper”and Player 2 choses “Rock”. Player 1 wins (As paper covers Rock).
- If Player 1 chooses “Paper”and Player 2 choses “Scissor”. Player 2 wins (As scissor cuts paper).
- If Player 1 chooses “Rock”and Player 2 choses “Scissor”. Player 1 wins (As Rock can’t be cut by scissor).
- If both player choose same choice. It’s a Draw.
Now you have to write a program that makes this game. In a way that in main () you will only call functions and nothing else. Functions are:
- MENU()
- In this, you will show a user to select a choice that whether he/she wants to play with Human or Computer or wants to Exit.
1-Play with Human
2-Play with Computer
3-Exit Game
- The function will return a choice.
- On the Basis of the choice returned, call another function. playHuman(), playComputer() or exitGame().
- playHuman()
- In this you will take inputs from Player 1 and Player 2. According to the choices made. Decide who wins or lose or draw.
- After showing output. Ask the user again whether he wants to continue playing or not.
- If “Yes” play again. Otherwise “Exit”.
- playComputer()
- In this you will take choice from Player and call a function (with in playComputer(), call a function computerChoice()) that will return the random choice of computer about Paper, Scissor or Rock. According to the choices made., decide who wins or lose or draw.
- After showing output. Ask the user again whether he wants to continue playing or not.
- If “Yes” play again. Otherwise “Exit”.
- exitGame()
Exit will simply close the program.
...