“Great ability develops and reveals itself increasingly with every new assignment.”
Assignment Details: Create Functions where required. This Assignment will give you opportunity to grasp all your concepts at the beginner level. I assure you that if any programmer will be able to implement all these questions without getting help from peers and Internet ,he/she will be a really good programmer in future.
Assignment Detail | |
C++ Assignment | Create Functions where required. |
Total Questions: | 30 |
Details | Create Functions where required. This Assignment will give you opportunity to grasp all your concepts at the beginner level. I assure you that if any programmer will be able to implement all these questions without getting help from peers and Internet ,he/she will be a really good programmer in future. GOOD LUCK. :) |
Q1:
GRADE ANALYZER
PREAMBLE:
You are supposed to write a program that shall prompt the user to input the name of a student and his/her respective marks. The input should be taken for a total of ten students.
OBJECTIVE:
Your program should calculate the average marks of this set of data; it also should print the list of respective grades achieved by this set of data, i.e. it should print the numbers of students with respect to each grade, and this number should be accompanied by the name and the marks of the student.
GRADING SCHEME 90>= GRADE =<100=A 80>= GRADE =<89=B 70>= GRADE =<79=C 60>= GRADE =<69=D 50>= GRADE =<59=E 00>= GRADE =<50=F |
SAMPLE OUTPUT:
Name : Student A
Marks: 97
Name: Student B
Marks: 90
Name: Student C
Marks: 84
Name: StudentD
Marks: 80
Number of ‘B’ Grades: 2
Number of ‘A’ Grades: 2
NOTE: Use an integer array to store their marks.
If the name of a student is in the index, x, then the xth index of the integer array should contain his\her marks.
>make functions to evaluate the numbers of grades received, i.e.
Intnumbofa(int *marks);
>make a function to print the names and marks of students with respect to their grades
Void printname(parameters);
>also create a menu to prompt a user to select option for print grade or marks or name or all of these.
>print the name according to the grades and marks if some
Q2:
Write a program, in which you have to find the distance between two points, given by the coordinates (x1, y1) and (x2, y2). By the definition,
Distance=? |
Take the values from the user of x1, y1, x2, y2 variables of double type. Make a function which computes and displays the distance by taking four parameters: x1, y1, x2, y2.
Note:
>you have to create function for input and calculate distance and also create a function that gives output.
Q3:
The area of triangle is: =1/2(b x h) where b is the base and h is the height. Write a complete program which includes the following three functions:
a. takebase: a function that inputs the base from the user and returns to main function
b. takeheight: a function that inputs the height from the user and returns to main function
c. area_of_triangle: the base and height are passed to this function as arguments and this function calculates and returns the area of a triangle in another output function.
Q4:
Write a program that will inputs the five digit number, separate the number into its individual digits and print the digits separated from one another by three spaces each after separation create a function that tell the number is Armstrong or not.
Q5:
A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data are transmitted as digit-integers. They have asked you to write a program that encrypts their data so that it can be transmitted more securely. Your program should read a four-digit-integer and encrypt it as follows:
Replace each digit by (sum of that digit with 7) modulus 10. Then, swap the first digit with the last, swap second digit with the second
Last and print the encrypted number.
Note:
>create a menu that accepts option for encryption and decryption from the user
>your program should be work if I enter 10 digit integer so create a logic in which user can encrypt and decrypt any large integer
>create a function for encryption and decryption
>decryption means changing the number into its original form
Q6:
Make a program that will print truth table of AND, OR and NOT. The user will enter
1 for AND
2 for OR
3 for NOT
Use switch for this purpose, also ask the user to enter 0 & 1 and display the result for respective logical operator.
A teacher would like his students to play a small game. The rules of the game require that the students be divided into 4 groups (Red, Green, Blue and Purple) based on the following information for each student:
1. The roll number of the student – not more than 3 digits long and ranging between 1 and 400
2. The score of the student the last time he played this game (scores will be between 0 and 100)
Your task is to write a program that automatically decides the new group of the student when the above information is entered. Your program must take into consideration the following rules for group assignment:And score between | The assign this group | |
1 and 100 | 0 and 25 | RED |
26 and 50 | GREEN | |
51 and 75 | BLUE | |
76 and 100 | PURPLE | |
101 and 200 | 0 and 25 | GREEN |
26 and 50 | RED | |
51 and 75 | PURPLE | |
76 and 100 | BLUE | |
201 and 300 | 0 and 25 | PURPLE |
26 and 50 | BLUE | |
51 and 75 | RED | |
76 and 100 | GREEN | |
301 and 400 | 0 and 25 | BLUE |
26 and 50 | PURPLE | |
51 and 75 | GREEN | |
76 and 100 | RED |
Hint: There are four ways through which a student might end up in any one group – try to formulate your conditions by keeping that in mind.
Q8:Program to accept a string and count no of capital letters, no. of small letters and no. of special characters. And also tell how many times space occurred between the string
Note:>create separate functions for counting each type. Those who already implemented this try to use built in functions for this question available in
Take input in a string and print the string in forward and reverse order. Take input in a string. Then print the number of vowels present in the string. A palindrome is a text phrase that reads the same backwards as forwards, For Example, Madam; from both sides it’s same? Write a program which will tell that entered string is palindrome or not. Make a function which takes a character array entered by user prints whether string is palindrome or not.(Try to use pointers)
Q10:
A palindrome is a number that reads the same backwards as forwards, For Example, each of the following number is a palindrome 12321, 55555, 45554, 11611. Write a program that gets a number from user and pass it to a function, which will print whether number is palindrome, or not (Hint: Use Modulus and Division operator to separate the numbers).
Q11:
Write a program than take a number and show its 30 multiples in rows and column
e.g.
Enter number: 5
5 10 15 20 25
30 35 40 45 50
and so on
Q12:
Find prime numbers between two numbers in Ascending and descending order.
Q13:
Suppose all the electric lights of your house has been blown up and you called an electrician to adjust new lights, the electrician will tell you the total number of lights to be replaced and the price of each light and also the charges of his placing one light.
You have to print the total bill that you have to pay to the electricians.
Beside all that the electrician is also offering some discounts if you will replace 10 – 19 lights by the electrician then he will give you 10% discount from the total charges of replacing lights and if 20 – 25 then he will offer you 15% discount on total charges of replacing lights and 20% discount on replacement of more than 25 lights.
Q14:
Suppose that an International Fighting match is going to be held in December 2007. You are a member of the selection committee and the rules for selecting the fighters are:
Weight should be from 80 – 150 Kg.
Total Matches should not be less than 50 matches.
And he has not been injured more than 40% in all previous matches.
You have to get the weight, total matches and injured in previous matches of the applicant and check whether the applicant is illegible or legible to participate in the fighting match.
Remember you have to get the total number of matches in which he has been injured in injury category and then get the Percentage by using formula
Injury = (Matches in which he has been injured / total
Matchesplayed) * 100.
Now select which player is Legible and which is not.
Write a program that will print the multiples of the given number and divide them in rowsand columns. (You can use escape sequences)
Q15:
Write a program to add, subtract, multiply and divide two fractions.
Q16:
Write a program in C++ to find X^y (X power Y)
Q17:
Drivers are concern with mileage obtained by their auto mobiles. 1 driver has kept track of several tanks full of Petrol by recording miles driven and gallons used for each tankful. Develop a C++ program that will input miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information the program should calculate and print the combined miles per gallon obtained for all tanks full.
e.g.
Enter the Gallons used (-1 to end): 12.8
Enter Miles Driven: 287
The Miles per Gallon for this tank was: 22.421875
Enter the Gallons used (-1 to end): 10.3
Enter Miles Driven: 200
The Miles per Gallon for this tank was: 19.417475
Enter the Gallons used (-1 to end): 5
Enter Miles Driven: 120
The Miles per Gallon for this tank was: 24.000000
Enter The Gallons used (-1 to end): -1
The overall average miles per gallon was: 21.601423
Q18:
Write a program that will get a number from user and print box according to that number.
e.g.
Enter a Number: 7
*******
*******
*******
*******
*******
*******
*******
Q19
Write program that will input an integer from user until the user enter (-1):
Calculate the sum and average of all numbers.
Enter any integer: 21
Enter any integer: 19
Enter any integer: 12
Enter any integer: 4
Enter any integer: -1
Sum=56
Average=14
Q20:
Write a function called hts( ) that takes three int values for hours, minutes, and seconds as arguments, and returns the equivalent time in seconds (type long). Create a program that implements this function by repeatedly obtaining a time value in hours, minutes, and seconds from the user (format 12:59:59), calling the function, and displaying the value of seconds it returns until a user press 0.
Q21:
Write a function called zeroSmaller() that is passed two int arguments by reference and then sets the smaller of the two numbers to 0.
Q22:
Write a function that, when you call it, displays a message telling how many times it has been called: “I have been called 3 times”, or whatever. Write a main () program that calls this function at least 10 times.
Q23:
Write a function called reversit() that reverses a C-string (an array of char). Use for loop that swaps the first and last characters, then the second and next-to-last characters, and so on. The string should be passed to reversit() as an argument.
Q24:
Write a function that copy one string to other i.e. given a source string copy it into destination. The prototype for the function is given as
Char * mystringcopy( char * source,char * destination)
Q25:
Write a complete program that inputs a positive integer n and then prints a triangle of asterisks of lines n.
Sample Output: Enter No: 5
*
***
*****
*******
*********
Q26:
A monthly magazine wants a program that will print out renewal notices to its subscribers and cancellation notices when appropriate. Using functions when needed, write a program that first reads in
The current month number (1 through 12) and
Year (0000 through 9999).
For each subscription processed, read in four data items:
The account number,
The month and
Year the subscription started, and
The number of years paid for the subscription.
Read in each set of subscription information and print a renewal notice if the current month is either the month prior to expiration or the month of expiration. A cancellation notice should be printed if the current month comes after the expiration month.
Sample input might be:
10, 1999
1364, 4, 1997, 3
NOTE:
Do all possible error checking.
Continue running the program until asked by the user to stop
You must use functions and pointers to do this assignment. Skeleton code is being provided to you. You must follow this skeleton to do the assignment i.e. the name of functions and the tasks that each function performs must be the same as has been outlined here. The parameters list should also be the same as has been outlined here. Your main function should also be the same as has been given here. As you can figure out after looking at the code, you have to use functions and pass pointer variables to these functions.
Functions prototypes and main function:
voidreadMonthYear(int *currentmonth, int *currentyear)
{
//user should enter current month and current year here
}
voidreadSubscriptionInfo(int *account, int *startmonth, int *startyear, int *yearspaid)
{
// user should enter account number, start month, start year and years paid here
}
voidprintNotice(int *account, int* startmonth, int*startyear, int *yearspaid)
{
//this is the function where decision has to be made whether to print renewal or cancellation //notice
}
int main(intargc, char* argv[])
{
//your main should exactly be like this
cout<< "Magazine Subscription\n";
intcurrentmonth;
intcurrentyear;
int account;
intstartmonth;
intstartyear;
intyearspaid;
// read in current month and year
readMonthYear(¤tmonth, ¤tyear);
// for each subscription read in subscription info
readSubscriptionInfo(&account, &startmonth, &startyear, &yearspaid);
// print renewal/cancellation notice
printNotice(&account, &startmonth, &startyear, &yearspaid);
Return 0;
}
Q27:
What's your sign? Write a program sign.cpp that takes two integers M and D and prints the Zodiac sign corresponding to month M (1 = January, 12 = December) and day D. Use the following table
SIGN | FROM | TO |
Capricorn | December 22 | January 19 |
Aquarius | January 20 | February 17 |
Pisces | February 18 | March 19 |
Aries | March 20 | April 19 |
Taurus | April 20 | May 20 |
Gemini | May 21 | June 20 |
Cancer | June 21 | July 22 |
Leo | July 23 | August 22 |
Virgo | August 23 | September 22 |
Libra | September 23 | October 22 |
Scorpio | October 23 | November 21 |
Sagittarius | November 22 | December 21 |
Q28:
Write a program that take an input an integer value A and print the sum of the digits in it.
Enter a Number 123 Sum of digits is 6 |
Q29:
Write a program that in a loop prompts the user to enter an integer, say X, and then prints the first X capital letters in reverse order. The loop terminates when X is less than 1. If X is greater than 26 then by seeing the sample input &output given below decide what to do. Case # 3 will give u the hidden information. You have to make function to solve this problem
Here is a sample run of your program: Enter value for X: 5
EDCBA
Enter value for X: 9
IHGFEDCBA
Enter value for X: 30
DCBAZWYXVUTSRQPONMLKJIHGFEDCBA
Enter value for X: -3
Good Bye
Q30:
You have to write a program to aid in the selection of a cricket team. Your program will take the following information as input:
- Batting average (greater than or equal to 0)
- Bowling average (greater than or equal to 0)
- Type of Bowler (‘f’ for fast bowler and‘s’ for spinner)
- Batting strike rate (greater than 0)
- Economy rate (greater than or equal to 0)
Based on this information, you have to decide three things:
- Is he a batsman? If yes, then should he be playing in Tests or in ODIs?
- If not a batsman, is he a bowler? If yes, then should he be playing in Tests or in ODIs?
- If he is both, then should he be playing in Tests or in ODIs?
If the stats of a player are such that he cannot be put into any of the above three categories, then your program should state that the player should be part of the Reserves.
A player should be categorized as a Batsman,
If his batting average is greater than or equal to 45 AND his bowling average is greater than or equal to 60.
A player should be categorized as a Bowler (regardless of his type),
If his bowling average is less than or equal to 30 AND his batting average is less than 20.
A player should be categorized as an All-rounder
If his batting average is greater than or equal to 40 AND his bowling average is less than or equal to 30.
Now, a Batsman should play in a Test side,
If his batting average is greater than or equal to 50 AND his strike rate is less than or equal to 70. If this is not the case then he should play in ODIs.
In case of a Bowler,
If he is a spinner AND his average is between 20 and 30 (both inclusive) AND his economy rate is less than or equal to 3 then he should play in a Test side – otherwise in ODIs.
If he is a fast bowler AND his average is between 20 and 30 (both inclusive) AND his economy rate is less than or equal to 5 but greater than 3 then he should play in ODIs – otherwise in Tests.
For an All-rounder
If the batting average is greater than or equal to 40 AND the bowling average is less than or equal to 25 then he should be playing in Tests – otherwise in ODIs.
In addition,
1. Your program must handle all exceptional cases
2. Your program must be properly commented
3. Your program must contain the appropriate file header
Note: File header means – your name, roll no, filename, date of creation and a brief description stating what the file is supposed to accomplish
Extra Credit:
Modify your program so that it now also tries to determine whether the player is a wicket-keeper or not. For this purpose, make your program accept the following information as well:
- - Number of catches taken by the player
- - Number of run-outs performed
- - Number of matches played so far
If the ratio between the number of catches taken and matches played is greater than or equal to ½ AND the ratio between number of run-outs performed and matches played is greater than or equal to 10% then the player is a wicket-keeper.
Also, if this player’s batting average is greater than or equal to 35 AND his batting-strike rate is greater than or equal to 80, he should be played in ODIs. If that is not the case, but his average is greater than or equal to 35 AND his strike rate is greater than or equal to 50, then he should be played in Tests – otherwise he should be put into reserves.
Question 31: Write the following function and implement these functions in a sample program. (Don’t use built-in Library,inorder to understand the behavior of these functions first use them usingh builtin string.h header file) (5x12=60 points)
- Void Strcpy(char*str1, char*str2)
// this function will copy the “str1” to” str2”
- Char*Strcat(char*str1,char*str2)
// this function will concatenate “str1” and” str2” and return the new string
- Int Strcmp(char*str1, char*str2)
// this function will compare both string (IGNORE CASE). If both are equal then return 1 otherwise 0
- Int Strcmpi(char*str1, char*str2)
// this function will compare both string (DON’T IGNORE CASE). If both are equal then return 1 otherwise 0
- Char*Strstr(char*str, int start, int end)
// function will return the “str” part from “start” index to “end” index
- Char*Strrev(char *str)
// function will make reverse the “str” String and return it
- Char*Strtok(char*str,char ch)
// function will split the “str” string from “ch” character and convert it into char* Array and return it
- Int Strlen(Char*str)
// function will return the length of “str” String
- Int StrStart(char*str,char*start)
// function check if the “str” string will start with “start” string then it will return 1 otherwise return 0
- Int StrEnd(char*str,char*end)
// function check if the “str” End will start with “end” string then it will return 1 otherwise return 0
- Int StrFind(char*str,char*f)
// function find the String “f” in String “str”. If string is found then it will return 1 otherwise 0
- Int CharFind(char*str,char f)
// function find the character “f” in string “str”, If character is found then return 1 otherwise 0
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.