0% found this document useful (0 votes)
4 views8 pages

PracticeQuestionsforCS101 SpecialTest

The document contains a series of practice questions for a CS101 special test, each requiring the creation of a C++ program to solve various problems. Topics include calculating perimeter, average speed, checking number signs, categorizing books, determining age groups, calculating factorials, summing even numbers, generating multiplication tables, printing patterns, calculating quiz averages, finding minimum and maximum values, counting houses within a budget, and converting Celsius to Fahrenheit. Each question includes sample inputs and expected outputs for testing purposes.

Uploaded by

krishayrodge765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

PracticeQuestionsforCS101 SpecialTest

The document contains a series of practice questions for a CS101 special test, each requiring the creation of a C++ program to solve various problems. Topics include calculating perimeter, average speed, checking number signs, categorizing books, determining age groups, calculating factorials, summing even numbers, generating multiplication tables, printing patterns, calculating quiz averages, finding minimum and maximum values, counting houses within a budget, and converting Celsius to Fahrenheit. Each question includes sample inputs and expected outputs for testing purposes.

Uploaded by

krishayrodge765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

‭Practice Question for CS101 Special Test‬

‭ uestion 1 - Perimeter‬
Q
‭Question 2 - Speed‬
‭Question 3 - Positive, Negative, Zero‬
‭Question 4 - Library‬
‭Question 5 - Age‬
‭Question 6 - Factorial‬
‭Question 7 - Sum even numbers from 1 to N‬
‭Question 8 - Multiplication tables‬
‭Question 9 - Pattern‬
‭Question 10 - Quiz Average‬
‭Question 11 - Minimum and Maximum‬
‭Question 12 - Count less than N‬
‭Question 13 - Count even and odd‬
‭Question 14 - Celsius to Fahrenheit‬
‭Question 15 - Sum of the square of digits‬
‭Question 16 - Circle‬
‭Question 17 - Resize rectangle‬
‭Question 18 - Struct Rectangle‬
‭Question 19 - Struct Grade‬
‭Question 20 - Struct Book‬
‭Question 1 - Perimeter‬
‭ rite‬‭a‬‭C++‬‭program‬‭to‬‭accept‬‭two‬‭integers‬‭representing‬‭the‬‭length‬‭and‬‭breadth‬‭of‬‭a‬‭rectangle‬‭as‬‭input‬‭from‬‭the‬
W
‭user. Calculate and print the perimeter of the rectangle.‬
‭(‬‭
2 * (length + breadth)‬ ‭)‬

‭ est Cases:‬
T
‭- Input: 5 3‬
‭Output: 16‬
‭- Input: 7 2‬
‭Output: 18‬
‭- Input: 10 10‬
‭Output: 40‬

‭Question 2 - Speed‬
‭ aj‬ ‭went‬‭to‬‭Matheran‬‭on‬‭a‬‭cycle‬‭last‬‭week.‬‭He‬‭traveled‬‭for‬‭a‬‭distance‬‭D.‬‭Once‬‭he‬‭reached‬‭his‬‭destination,‬‭he‬
R
‭realized‬ ‭that‬ ‭it‬ ‭took‬ ‭a‬ ‭total‬ ‭of‬ ‭T‬ ‭hours.‬ ‭He‬ ‭is‬ ‭curious‬ ‭as‬ ‭to‬ ‭how‬ ‭fast‬ ‭he‬ ‭was‬ ‭cycling,‬ ‭for‬ ‭which‬ ‭he‬ ‭wants‬ ‭to‬
‭calculate‬ ‭average‬ ‭speed‬ ‭in‬ ‭km/hr‬ ‭using‬ ‭the‬ ‭formula:‬‭speed‬‭=‬‭distance‬‭/‬‭time.‬‭Write‬‭a‬‭C++‬‭program‬‭to‬‭input‬‭D‬
‭and T and print the speed.‬

‭ est Cases:‬
T
‭- Input: 100 2‬
‭Output: 50‬
‭- Input: 150 3‬
‭Output: 50‬
‭- Input: 200 4‬
‭Output: 50‬

‭Question 3 - Positive, Negative, Zero‬


‭Seema has a number and she wants to check if it is positive, negative, or zero. Write a C++ program to help her.‬

‭ est Cases:‬
T
‭- Input: 5‬
‭Output: Positive‬
‭- Input: -3‬
‭Output: Negative‬
‭- Input: 0‬
‭Output: Zero‬
‭Question 4 - Library‬
‭ ou‬‭are‬‭helping‬‭a‬‭librarian‬‭categorize‬‭books.‬‭If‬‭the‬‭book's‬‭genre‬‭is‬‭"fiction,"‬‭print‬‭"This‬‭is‬‭a‬‭fictional‬‭book."‬‭If‬‭the‬
Y
‭genre is "non-fiction," print "This is a non-fictional book." Otherwise, print "‬‭ Genre unknown.‬ ‭"‬

‭ est Cases:‬
T
‭- Input: fiction‬
‭Output: This is a fictional book‬
‭- Input: non-fiction‬
‭Output: This is a non-fictional book.‬
‭- Input: mystery‬
‭Output: Genre unknown.‬

‭Question 5 - Age‬
‭ rite‬‭a‬‭C++‬‭program‬‭to‬‭input‬‭age.‬‭If‬‭the‬‭age‬‭is‬‭less‬‭than‬‭13,‬‭print‬‭"You‬‭are‬‭a‬‭child."‬‭If‬‭the‬‭age‬‭is‬‭between‬‭13‬‭and‬
W
‭19, print "You are a teenager." If the age is 20 or older, print "You are an adult."‬

‭ est Cases:‬
T
‭- Input: 10‬
‭Output: You are a child.‬
‭- Input: 16‬
‭Output: You are a teenager.‬
‭- Input: 25‬
‭Output: You are an adult.‬

‭Question 6 - Factorial‬
‭Write a program that calculates the factorial of a number n (0 to 10) given by the user.‬

‭ est Cases:‬
T
‭- Input: 5‬
‭Output: 120‬
‭- Input: 3‬
‭Output: 6‬
‭- Input: 1‬
‭Output: 1‬
‭Question 7 - Sum even numbers from 1 to N‬
‭ ou‬‭decide‬‭to‬‭host‬‭a‬‭small‬‭picnic‬‭with‬‭your‬‭friends‬‭in‬‭the‬‭park.‬‭As‬‭you‬‭plan‬‭the‬‭snacks,‬‭you‬‭want‬‭to‬‭make‬‭sure‬
Y
‭you‬‭have‬‭enough‬‭even-numbered‬‭sandwiches‬‭for‬‭everyone,‬‭so‬‭you‬‭start‬‭counting.‬‭You‬‭decide‬‭to‬‭sum‬‭up‬‭all‬‭the‬
‭even‬‭numbers‬‭from‬‭1‬‭to‬‭the‬‭total‬‭number‬‭of‬‭sandwiches‬‭you‬‭plan‬‭to‬‭make,‬‭just‬‭to‬‭see‬‭how‬‭many‬‭you’ll‬‭need‬‭for‬
‭the‬ ‭picnic.‬ ‭Write‬ ‭a‬ ‭C++‬ ‭program‬ ‭to‬ ‭input‬ ‭N‬ ‭(the‬ ‭total‬ ‭number‬ ‭of‬ ‭sandwiches)‬ ‭and‬ ‭print‬ ‭the‬ ‭sum‬ ‭of‬ ‭all‬ ‭even‬
‭numbers from 1 to N.‬

‭ estcases:‬
T
‭Input: 6‬
‭Output: 12 (2 + 4 + 6)‬
‭Input: 10‬
‭Output: 30 (2 + 4 + 6 + 8 + 10)‬
‭Input: 5‬
‭Output: 6 (2 + 4)‬

‭Question 8 - Multiplication tables‬


‭ uppose‬‭you‬‭are‬‭creating‬‭software‬‭to‬‭help‬‭school‬‭children‬‭learn‬‭multiplication‬‭tables.‬‭Write‬‭a‬‭C++‬‭program‬‭that‬
S
‭inputs a number, n, and prints its multiplication table (from 1 to 10).‬

‭ est Cases:‬
T
‭- Input: 2‬
‭Output: 2 4 6 8 10 12 14 16 18 20‬
‭- Input: 5‬
‭Output: 5 10 15 20 25 30 35 40 45 50‬
‭- Input: 3‬
‭Output: 3 6 9 12 15 18 21 24 27 30‬

‭Question 9 - Pattern‬
‭Write a program that prints a right-angled triangle pattern of stars. The number of rows will be provided as input.‬

‭‬
*
* *‬

* * *‬

‭ est cases‬
T
‭Input: 3‬
‭Output:‬
‭*‬
‭* *‬
‭* * *‬
‭Input: 5‬
‭Output:‬
‭*‬
‭* *‬
‭* * *‬
‭* * * *‬
‭* * * * *‬
‭Question 10 - Quiz Average‬
‭ S101‬‭theory‬‭quiz‬‭was‬‭conducted.‬‭The‬‭instructor‬‭wants‬‭to‬‭know‬‭the‬‭average.‬‭You‬‭are‬‭tasked‬‭with‬‭this‬‭activity.‬
C
‭Write‬ ‭a‬ ‭C++‬ ‭program‬ ‭to‬ ‭accept‬ ‭N‬ ‭i.e.‬ ‭the‬ ‭number‬ ‭of‬ ‭students,‬ ‭followed‬ ‭by‬ ‭N‬ ‭floating‬ ‭point‬ ‭numbers‬ ‭that‬
‭represent‬‭the‬‭score‬‭of‬‭the‬‭student.‬‭Print‬‭the‬‭average.‬‭Assume‬‭that‬‭N‬‭will‬‭be‬‭between‬‭1‬‭and‬‭100,‬‭both‬‭inclusive‬
‭and marks will be between 1 and 14, both inclusive.‬

‭ estcases‬
T
‭Input: 5 12.5 10.0 14.0 9.5 11.0‬
‭Output: 11.4 ((12.5 + 10.0 + 14.0 + 9.5 + 11.0)/5)‬

I‭nput: 3 7.0 8.0 6.0‬


‭Output: 7.0‬

I‭nput: 4 13.5 10.5 14.0 11.0‬


‭Output: 12.25‬

‭Question 11 - Minimum and Maximum‬


I‭n‬‭a‬‭recent‬‭cricket‬‭match‬‭between‬‭India‬‭and‬‭Australia,‬‭you‬‭need‬‭to‬‭analyze‬‭the‬‭performance‬‭of‬‭Indian‬‭batsmen.‬
‭Write‬ ‭a‬ ‭C++‬ ‭program‬ ‭that‬ ‭takes‬ ‭the‬ ‭runs‬ ‭scored‬ ‭by‬ ‭each‬ ‭Indian‬ ‭player‬ ‭in‬ ‭an‬ ‭array‬ ‭and‬ ‭determines‬ ‭both‬ ‭the‬
‭maximum and minimum runs scored by any player. It is assumed that all players had the opportunity to bat.‬

‭ estcases‬
T
‭Input: 10 45 67 89 23 56 78 34 12 90 11‬
‭Output: 90 10‬
‭Input: 60 100 200 150 80 60 90 30 40 120 110‬
‭Output: 200 30‬
‭Input: 32 15 25 35 5 55 65 75 85 95 45‬
‭Output: 95 5‬

‭Question 12 - Count less than N‬


‭ aj‬‭and‬‭Simran‬‭are‬‭looking‬‭for‬‭a‬‭house‬‭to‬‭rent.‬‭They‬‭have‬‭set‬‭a‬‭budget‬‭limit‬‭for‬‭the‬‭monthly‬‭rent‬‭they‬‭can‬‭afford.‬
R
‭After‬ ‭visiting‬ ‭a‬ ‭certain‬ ‭number‬ ‭of‬‭houses,‬‭they‬‭want‬‭to‬‭know‬‭how‬‭many‬‭of‬‭these‬‭houses‬‭have‬‭rent‬‭within‬‭their‬
‭budget.‬‭Write‬‭a‬‭C++‬‭program‬‭to‬‭input‬‭the‬‭budget‬‭limit‬‭B‬‭(an‬‭integer),‬‭the‬‭number‬‭of‬‭houses‬‭they‬‭visited‬‭N,‬‭and‬
‭the‬‭rent‬‭(an‬‭integer)‬‭for‬‭each‬‭of‬‭these‬‭N‬‭houses.‬‭The‬‭program‬‭should‬‭output‬‭the‬‭count‬‭of‬‭houses‬‭that‬‭fall‬‭within‬
‭their budget.‬

‭ estcases‬
T
‭Input: 5000 5 4000 6000 3500 5000 7000‬
‭Output: 3‬
‭Explanation:‬
‭- Budget limit B = 5000‬
‭- House rents: 4000, 6000, 3500, 5000, 7000‬
‭- 3 houses (4000, 3500, and 5000) are within or equal to the budget.‬
‭Input: 3000 4 2500 1500 3500 2000‬
‭Output: 3‬
‭Input: 10000 6 8000 12000 9000 15000 10000 9500‬
‭Output: 4‬
‭Question 13 - Count even and odd‬
‭ umbai‬ ‭city‬ ‭is‬ ‭known‬ ‭for‬ ‭its‬ ‭fast‬ ‭life‬ ‭and‬ ‭a‬ ‭lot‬ ‭of‬ ‭traffic.‬ ‭The‬ ‭city‬ ‭also‬ ‭faces‬ ‭issues‬ ‭due‬‭to‬‭the‬‭limited‬‭parking‬
M
‭space.‬‭To‬‭solve‬‭this‬‭problem,‬‭CS‬‭101‬‭students‬‭came‬‭up‬‭with‬‭the‬‭idea‬‭that‬‭each‬‭parking‬‭lot‬‭be‬‭given‬‭a‬‭number.‬
‭The‬ ‭cars‬ ‭with‬ ‭even‬ ‭license‬‭plate‬‭numbers‬‭should‬‭be‬‭parked‬‭in‬‭the‬‭even-numbered‬‭parking‬‭lot,‬‭and‬‭those‬‭with‬
‭odd‬‭license‬‭plate‬‭numbers‬‭should‬‭be‬‭parked‬‭in‬‭the‬‭odd-numbered‬‭parking‬‭lot.‬‭However,‬‭we‬‭must‬‭first‬‭determine‬
‭how‬ ‭many‬ ‭cars‬ ‭have‬ ‭even‬ ‭and‬ ‭odd‬ ‭license‬ ‭plate‬ ‭numbers.‬ ‭Write‬‭a‬‭C++‬‭program‬‭that‬‭inputs‬‭the‬‭license‬‭plate‬
‭numbers (1001 to 9999) in an array. Print the count of cars having even and odd license plates.‬

‭ estcases‬
T
‭- Input: 3 1001 2002 3003‬
‭Output: 1 2‬
‭- Input: 4 1234 5678 9101 1121‬
‭Output: 2 2‬
‭- Input: 5 1357 2468 9753 8642 1359‬
‭Output: 2 3‬

‭Question 14 - Celsius to Fahrenheit‬


‭ rite‬‭a‬‭C++‬‭program‬‭to‬‭input‬‭the‬‭temperature‬‭in‬‭Celsius‬‭as‬‭a‬‭floating-point‬‭number‬‭in‬‭the‬‭main‬‭function.‬‭Pass‬‭it‬
W
‭to‬ ‭a‬ ‭function‬ ‭called‬ ‭‘convert’.‬ ‭In‬ ‭the‬ ‭function,‬ ‭convert‬ ‭the‬ ‭temperature‬ ‭to‬ ‭Fahrenheit‬ ‭and‬ ‭print‬ ‭the‬ ‭result.‬
‭(Formula: Fahrenheit = Celsius * (9/5) + 32)‬

‭ est Cases:‬
T
‭- Input: 0‬
‭Output: 32‬
‭- Input: 25‬
‭Output: 77‬
‭- Input: -10‬
‭Output: 14‬

‭Question 15 - Sum of the square of digits‬


‭ ayCart‬ ‭is‬ ‭an‬ ‭online‬ ‭shopping‬ ‭platform‬ ‭that‬ ‭offers‬ ‭various‬ ‭discount‬ ‭schemes‬ ‭to‬ ‭its‬ ‭users.‬ ‭The‬ ‭latest‬ ‭scheme‬
Y
‭allows‬‭customers‬‭to‬‭receive‬‭a‬‭discount‬‭based‬‭on‬‭the‬‭sum‬‭of‬‭the‬‭squares‬‭of‬‭the‬‭digits‬‭of‬‭the‬‭total‬‭cost‬‭of‬‭items‬‭in‬
‭their‬ ‭cart.‬ ‭Specifically,‬ ‭the‬ ‭calculated‬ ‭sum‬ ‭is‬ ‭subtracted‬ ‭from‬ ‭the‬ ‭original‬ ‭cost‬ ‭to‬ ‭determine‬ ‭the‬ ‭final‬ ‭amount‬
‭payable.‬ ‭Write‬ ‭a‬ ‭C++‬ ‭program‬ ‭that‬ ‭accepts‬ ‭the‬ ‭number‬ ‭of‬ ‭customers,‬ ‭N,‬ ‭who‬ ‭are‬ ‭checking‬ ‭out.‬ ‭For‬ ‭each‬
‭customer,‬‭input‬‭the‬‭cost‬‭(positive‬‭integers)‬‭of‬‭their‬‭items.‬‭Pass‬‭the‬‭cost‬‭to‬‭a‬‭function‬‭that‬‭computes‬‭and‬‭returns‬
‭the‬ ‭discount.‬ ‭Output‬ ‭the‬ ‭final‬ ‭amount‬ ‭the‬‭customer‬‭needs‬‭to‬‭pay‬‭after‬‭applying‬‭the‬‭discount.‬‭Assume‬‭that‬‭the‬
‭sum of the squares of the digits of the number (cost) will always be less than the actual cost.‬

‭ estcases‬
T
‭- Input: 2 150 998‬
‭Output: 124 772‬
‭- Input: 3 2674 100 90‬
‭Output: 2569 99 9‬
‭- Input: 4 874 123 962 556‬
‭Output: 745 109 841 470‬
‭Question 16 - Circle‬
‭ rite‬‭a‬‭C++‬‭program‬‭that‬‭takes‬‭the‬‭radius‬‭of‬‭a‬‭circle‬‭as‬‭input.‬‭Pass‬‭the‬‭radius‬‭to‬‭a‬‭function‬‭that‬‭calculates‬‭the‬
W
‭diameter, circumference, and area of the circle. Finally, display these results in the main function.‬

‭ estcaess‬
T
‭- Input: 5‬
‭Output: 10 31.4159 78.5397‬
‭- Input: 7‬
‭Output: 14 43.9823 153.938‬
‭- Input: 3‬
‭Output: 6 18.8495 28.2743‬

‭Question 17 - Resize rectangle‬


‭ ‬‭strawberry‬‭farmer‬‭in‬‭Mahabaleshwar‬‭has‬‭a‬‭rectangular‬‭plot‬‭of‬‭land‬‭where‬‭he‬‭cultivates‬‭strawberries.‬‭The‬‭plot‬
A
‭is‬‭defined‬‭by‬‭its‬‭top‬‭left‬‭corner‬‭at‬‭coordinates‬‭(x1,y1)‬‭and‬‭bottom‬‭right‬‭corner‬‭at‬‭(x2,y2).‬‭The‬‭farmer‬‭has‬‭decided‬
‭to‬‭expand‬‭this‬‭plot‬‭and‬‭has‬‭chosen‬‭a‬‭resizing‬‭factor.‬‭However,‬‭he‬‭will‬‭keep‬‭the‬‭top‬‭left‬‭corner‬‭fixed.‬‭He‬‭is‬‭finding‬
‭it difficult to calculate and has asked you for help to compute the new coordinates (x2,y2).‬

‭ rite‬ ‭a‬ ‭C++‬ ‭program‬ ‭that‬ ‭accepts‬ ‭the‬ ‭coordinates‬ ‭x1,‬ ‭y1,‬ ‭x2,‬ ‭y2,‬ ‭and‬ ‭the‬ ‭factor,‬‭f,‬‭from‬‭the‬‭user‬‭in‬‭the‬‭main‬
W
‭function.‬‭Pass‬‭x1,‬‭y1,‬‭and‬‭factor‬‭by‬‭value,‬‭and‬‭x2‬‭and‬‭y2‬‭by‬‭reference‬‭to‬‭the‬‭function.‬‭In‬‭the‬‭function,‬‭compute‬
‭the updated coordinates and print the result in the main.‬

‭ estcases‬
T
‭- Input: 0 0 10 10 3‬
‭Output: 30 30‬
‭- Input: 2 3 5 7 2‬
‭Output: 8 11‬
‭- Input: 1 1 4 5 5‬
‭Output: 16 21‬

‭Question 18 - Struct Rectangle‬


‭ reate‬ ‭a‬ ‭struct‬ ‭Rectangle‬ ‭with‬‭two‬‭integer‬‭member‬‭variables:‬‭length‬‭and‬‭breadth.‬‭Write‬‭a‬‭function‬‭area‬‭inside‬
C
‭the‬‭struct‬‭that‬‭returns‬‭the‬‭area‬‭of‬‭the‬‭rectangle.‬‭Write‬‭a‬‭program‬‭to‬‭create‬‭a‬‭Rectangle‬‭object,‬‭input‬‭the‬‭length‬
‭and breadth, and print the area.‬

‭ est Cases:‬
T
‭- Input: 5 4‬
‭Output: 20‬
‭- Input: 6 7‬
‭Output: 42‬
‭- Input: 10 3‬
‭Output: 30‬
‭Question 19 - Struct Grade‬

‭ efine‬‭a‬‭struct‬‭Student‬‭with‬‭member‬‭variables‬‭name‬‭(string)‬‭and‬‭marks‬‭(integer).‬‭Write‬‭a‬‭function‬‭grade‬‭inside‬
D
‭the‬‭struct‬‭that‬‭returns‬‭'A'‬‭if‬‭marks‬‭are‬‭greater‬‭than‬‭or‬‭equal‬‭to‬‭75,‬‭'B'‬‭if‬‭between‬‭50‬‭and‬‭74,‬‭and‬‭'C'‬‭if‬‭below‬‭50.‬
‭Write a program to create a Student object, input the name and marks, and print the grade.‬

‭ est Cases:‬
T
‭- Input: John 85‬
‭Output: A‬
‭- Input: Alice 65‬
‭Output: B‬
‭- Input: Tom 45‬
‭Output: C‬

‭Question 20 - Struct Book‬

‭ efine‬‭a‬‭struct‬‭Book‬‭with‬‭member‬‭variables‬‭title‬‭(string),‬‭author‬‭(string),‬‭and‬‭price‬‭(float).‬‭Write‬‭a‬‭function‬‭display‬
D
‭inside‬‭the‬‭structure‬‭that‬‭prints‬‭the‬‭title‬‭and‬‭price‬‭of‬‭the‬‭book.‬‭Write‬‭a‬‭program‬‭to‬‭create‬‭a‬‭Book‬‭object,‬‭input‬‭the‬
‭title, author, and price, and display the title and price.‬

‭ est Cases:‬
T
‭- Input: C++_Primer Stanley 500.50‬
‭Output: C++_Primer 500.50‬
‭- Input: Algorithms CLRS 650.75‬
‭Output: Algorithms 650.75‬
‭- Input: Data_Structures Mark 300.00‬
‭Output: Data_Structures 300‬

You might also like