We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 43
‘question ner ®
Single File Programming Question
Imagine you ae developing a sotwore appiction thot torts anc manages the configuration settings for mule user profes. As part ofthis appcation youneed to creat a
‘los med "Demo te handle the review and printing of spree coniguration volves. Te "Dem ela shoul how the folowing species
Inincases wo pus tte ntger varies. ne which eprsent he configuration value
"he clots prover 9 ttle member tinction called get) thet allows othr pars fhe appication a retiows the value fx andy
‘he clase ato provides a static member tuncon ell tu) that pnt the values of Xend ¥ tothe cana
‘he default values farX end ¥ reset 10 and 20, respecte
‘Your tak to implement the"Deme’ cats bate on the ghven specications. nthe main methed of your application create an objct eth "Demo" lass and ea te "get(™
cna tn() meted to ratieve and pein the contiguation values, aspect,Note: This is a sample question asked in a Capgemini interview.
Input format :
The first line of input consists of the value of xX.
The second line of input consists of the value of Y.
Output format:
The first two lines of output print the default values of X and Y.
The last two lines of output print the given input values of X and Y
Refer to the sample outputs for the formatting specifications.
Code constraints :
The initial default values of X and Y are set to 10 and 20, respectively.
1<= x, ¥ <= 108Sample test cases :
Input 1
250
350
Input 2:
240
340
whitelist
Output!
Value of X:
Value of Y:
Value of x:
Value of Y:
Output
Value of x:
Value of Y:
Value of x:
Value of Y:
10
20
250
350
10
20
240
a4eCb atnes ay
Pate e Cr saa Pd
Pre eee
cree
Ere tey
Sree 3
Erie Caner an 2]
Tre tery
static int get() {
ire ae
yf
static void fun() {
Cree a ae
cout << “Value of Y
a es ee
Prarcstlo nesCotte Cy
static void fun() {
ror aaa aT MR ae CMMs Scan
cout << “value of Y: " << y << endl;
aeCy
oa
int main() {
eC seme tr ary
SU ReSseU) eam Ua io zy
Demo: : Fun() 5
Demo::x = inputx;
Demo::y - inputy;
Crane ES ae cM = cs Me EY
Cera Esl an eS eS eS
Cee 4ecommendedienmingcartnt: GpPsciez= | cPPLecim ates 3_cPP_ctmmeondomeces copia 24
tote Comet Mon ttsined fe ntvsnd 0 Tiree compled 2 Tanwnssbmited 1 level Kany Guatlontee ShglrBePogemming Sites! Coe
ope Clason ofa sub Tope Closter jess sons tomramy AREY
‘compler Mossogeeopteoat
ottnee opt
inet)
eres
Space Comply MeszogeaSolution 1
Purses Crier rors
using namespace std;
class Demo
i
Stree
Se-letelt 1a ¢]
static int Y;
Eset
static void get()
¢
te
static void fun()
{
fates enna]
eon aeeam TAT Lg Gd
eon eeean yh Mer aa!
<< X << endl;
oa aeeeeSolution 1
Petri
es Canna
static int Y;
PTISet
static void get()
a
Tipe cond
3
Seer m6)
tt
[naeeaa Tag << X << endl;
cout <<"Value of << ¥ << end];
i
Dae ae
int Demo :: Y =20;
int main()
Ky
ey
x.fun()3
Reader
x. fun();
cy‘oven?
Single Fle Programming Question
Areal ore wane cee nett oe an Rem hae oni umber nc cot here acne lah ence he Re ta and proves metodo cot th tl
‘com based ont quart
ete program ts cokeucethetotalco ot ontemboredan ke tem number ort aeetty urchazad,
Dene omembarurcton ouside th coe ston ae mas Kinney ut ug the oe nine nto Raoder ne oho anton ion
‘ete: hie samp question cneain Capgemini:
npattomet
‘hee onp const of antag epecrting th tren.
The sacodinectinpt condo eating poi umber raring the cot heim,
“Tralt ine cont of on tager representing ne quaaty he tm pura‘Output format:
A single-line output displaying the total cost of the item, formatted to two decimal places
Sample test cases:
Input}:
Frey
4.99
Input 2:
486
2.49
‘Output:
Total cost: 14.97
‘Output 2:
Total cost: 24.90Cone cy
Forrester rs
Estratr emeate rst ss
Pee ee
eros
pari
preety
yak ears
public:
Sree sto
Pee a Te Guan ee tate e
prea
cost = c;
a
inline float calculateTotalcost() {
return cost * quantity;
Ms
}
faa)GN ge)
}
ae geen Cea start O ee
}
Po ee TCLS as Fy
Umm
Saas eRes
Pa eee a
akin at
Paci ens as
SU eeeenc eee Stary
pes imeten ey eRenes Tee
item.quantity = quantity;
Coane sec Meee Tac nots e OT)
on Seca ce PCE Le act Kooy Mea od
anyott comet warkobtned ONO | vintsusd @ Tinescomplnd 4 | Tmesautmited | evel tay | Quetoniyee siglrRePrognming sitet cre
Tose lmetineton Subyopit imntimeten sear ane) ARPI
7) show testcase scores (7) show solution
owt
S/sTostcozes Passed
‘compiler Messageva ° sane = : : corpve ° cane = conpimton sits
eet
ve e sess = eoeeeaee
aSolution 1
suet mesi end
Potato cella be
Petraes Crist
isc eg
Pap hiyastd
CT em oad
gf aoors
Prise tay
Pee Cae ae a)
Piece Ceara ecosatia Tees)
i
RECOM eae Te -ieGae ae
De
nae
Ee trae cer Coe eae eta
Poa Cisne maar ed
:
int main() {
peecuesten 3 °
‘Single Fle Programming Question
Problem Statement
Artolhop wars tohaep vaso teases ter aspacic pared Tey needa reg ha lous thar olathe soles utr each ranacten andl totals
‘ourtoststo mite arogtamtocoeuete nd diay be tl soles mount of hep. The soo ses vous am and te Ses mount each te is redex ut YoU Pear shou
‘martan areca neta sos eres ltones fhe dls ing tat acta mabe on sae member uncon.
eters sorte quoston anes oDeoiteinens
spanner
‘helene oinpt coins an integer erecting the rumba stein
‘rennin contin th sles moun mos by soe anon oc Ie contains poste Hoang po vol
utptormat:
‘Te cuputconiasotasinge inectspcyng
tt sles amount the sopRefer to the sample output for the formatting specifications.
Code constraints
‘The number of sales instances should not exceed 100.
Each sales amount should be positive floating-point value.
‘Sample test cases :
Input:
3
100.5
50.75
15.25
25.5
30.75
15.28
20.5
Output:
Total Sales: 226.50
‘Output 2:
Total Sales: 92.00Cea Cy
#include
Put escorts
Petree re
re ae
anced
static float totalsales;
public:
lars
RR Occ CAC eg car ont
totalsales += amount;
ir
static float getTotalsales() {
return totalsales;
i
float Shop: :totalsales - 0.0;
Tat SULO net
int_n;Cette
a
static float gettotalsales()
patie evera ten
+
float shop: :totalsales = 0.03
rans UO nes
cay
neers
for (int i = 03 i
em |
Peat
ete eae reese
Prise ta
Seen CCC eee Coe
totalsales +- salesamount;
y
Seater ee aracs Onn
Paeea rye
Tat stlOnet
Tams
Eon ees cercaSolution 1
‘
CO Ras Peale ee
int main() {
Pars
Coes at
any
0; i