Skillrack Practice Problems 7

Solutions for Skillrack Code Test CSE1001 Practice Problems 7

24-Oct-2016 00:00 to  5-Nov-2016 00:00

Total time : 300 mins

Challenges : 5

Question 1 (Baking a bread)

A bakery prepares bread by following a sequence of operations, as listed in the table. All the operations should be performed to make a bread. The bakery prepares two types bread : White and Sweet bread. It prepares bread in two different sizes : single and double size. Further, breads are baked either by  a semi-automation  process ( that is, a few operations will be done by using machines and then the remaining operations done manually) or by an automation process (using machines for all the operations).

The following table details the time taken by the machine in performing the different operations involved in baking a single size  bread using machines. For Eg., the time taken to make a single size, white bread using machine, is 2 hrs 58 minutes and 2 seconds.  The time taken by the machine to prepare a double size bread , will be  50%  more of the time taken to prepare the single size bread using machines. For eg., if ‘primary kneading’ for a single size white bread requires 15 minutes, then, for the double size white bread, ‘primary kneading’ requires 22.5 minutes (22 minutes 30 seconds)

If baking is done by semi-automation process, use the machine till the ‘loaf-shaping cycle’ . Given the type of bread, size and type of baking, write an algorithm and the subsequent ‘C’ code to compute and display the time taken by the machine to prepare the bread.

Operation White Bread Sweet Bread
Primary Kneading 15 mins 20 mins
Primary rising 60 mins 60 mins
Secondary Kneading 18 mins 33 mins
Secondary rising 20 mins 30 mins
Loaf shaping 2 seconds 2 seconds
Final rising 75 mins 75 mins
Baking 45 mins 35 mins
Cooling 30 mins 30 mins

Input Format

First line contains the bread type (‘w’ or  ‘s’)

Next line contains the size of the loaf (‘1’ for single and ‘2’ for double)

Next line contains the type of baking (‘s’ for semi-automatic and ‘a’ for automatic)

Output Format

Print the duration in seconds, during which the machine is used .

Solution

#include < stdio.h >
int main()
{
    char x,m;
    int s,t;
    scanf("%c %d %c",&x,&s,&m);
    if(x=='w')
    {
        t=((15+60+18+20)*60)+2;
        if(m=='a')
        t+=(75+45+30)*60;
        if(s==2)
        t*=1.5;
    }
    else
    {
        t=((20+60+33+30)*60)+2;
        if(m=='a')
        t+=(75+35+30)*60;
        if(s==2)
        t*=1.5;
    }
    printf("%d",t);
    return(0);
}

Input

INPUT:

x - type of bread
s - size of loaf
m - type of making

Output

OUTPUT:

printf("%d",t);

Processing

if(x=='w')
    {
        t=((15+60+18+20)*60)+2;
        if(m=='a')
        t+=(75+45+30)*60;
        if(s==2)
        t*=1.5;
    }
    else
    {
        t=((20+60+33+30)*60)+2;
        if(m=='a')
        t+=(75+35+30)*60;
        if(s==2)
        t*=1.5;
    }

Pseudocode

BEGIN

Read x,s and m
if(x=='w')
    {
        t=((15+60+18+20)*60)+2;
        if(m=='a')
        t+=(75+45+30)*60;
        if(s==2)
        t*=1.5;
    }
    else
    {
        t=((20+60+33+30)*60)+2;
        if(m=='a')
        t+=(75+35+30)*60;
        if(s==2)
        t*=1.5;
    }
printf("%d",t);

END

Question 2 (Pattern)

Given an integer ‘n’, write an algorithm and the subsequent ‘C’ code to print a pattern with ‘2*(i-1)+1’ ‘#’es in the ith row. For example, if n is 4 then the pattern will look as follows:

#

###

#####

#######

Input Format

A number, n

Output Format

Print pattern

Solution

#include < stdio.h >
int main()
{
    int i,j,n;
    scanf("%d",&n);
    for(i=0;i < n;i++)
    {
        printf("\n");
        for(j=0;j < 2*(i)+1;j++)
        printf("#");
    }
    return(0);
}

Input

INPUT:

n - number of lines

Output

OUTPUT:
for(j=0;j < 2*(i)+1;j++)
        printf("#");

Processing

for(i=0;i < n;i++)
    {
        printf("\n");
        for(j=0;j < 2*(i)+1;j++)
        printf("#");
    }

Pseudocode

BEGIN

Read n
for(i=0;i < n;i++)
    {
        printf("\n");
        for(j=0;j < 2*(i)+1;j++)
        printf("#");
    }

END

Question 3 (Emission control)

The gases pollute the environment when they exceed the emission limit. There are two ranges of emission limit, one for the case when the odometer reads50000 miles or less than 50,000 miles and the other one is, when the odometer reads more than 50,000 miles. Odometer in a vehicle will display the total distance covered by the vehicle. Given the code of the gas, emission of gas in g/mile and the odometer reading, write an algorithm and the subsequent ‘C’ code to check if the emission has exceeded limit. Refer the below table of emission limits

Gas code and name First 50,000 Miles Second 50,000 Miles
 1 – Carbon Monoxide 3.4 g/mile 1.     g/mile
 2 – Hydrocarbons 0.31 g/mile 0.39/mile
 3 – Nitrogen oxides 0.4 g/mile 1.     g/mile
4 – Non-methane hydrocarbons 0.25 g/mile  0.31 g/mile

For example if the input is 2, 0.35, 40112 then the output is “Emission exceedsthe permitted level of 0.31 g/mile”

Input Format

First line contains the gas code

Next line contains the number of grams emitted per mile

Third line contains the odometer reading

Output Format

Print the following message

Emission exceedsthe permitted level of (value of emission limit)  g/mile

Or

Emission does not exceed the permitted level of (value of emission limit)  g/mile

Solution

#include < stdio.h >
int main()
{
    int c,o;
    int f=0;
    float g;
    float a[4][2]={3.4,1,0.31,0.39,0.4,1,0.25,0.31};
    scanf("%d %f %d",&c,&g,&o);
    if(o > 50000)
    f=1;
    if(g > a[c-1][f])
    printf("Emission exceeds the permitted level of %.2f g/mile",a[c-1][f]);
    else
    printf("Emission do not exceed the permitted level of %.2f g/mile",a[c-1][f]);
    return(0);
}

Input

INPUT:

c - gas code
g - grams per mile
o - odometer reading

Output

OUTPUT:
 if(g > a[c-1][f])
    printf("Emission exceeds the permitted level of %.2f g/mile",a[c-1][f]);
    else
    printf("Emission do not exceed the permitted level of %.2f g/mile",a[c-1][f]);

Processing

f=0;
if(o > 50000)
    f=1;

Pseudocode

BEGIN

Read c,g,and o
if(o > 50000)
    f=1;
    if(g > a[c-1][f])
    printf("Emission exceeds the permitted level of %.2f g/mile",a[c-1][f]);
    else
    printf("Emission do not exceed the permitted level of %.2f g/mile",a[c-1][f]);

Question 4 (Compute wages)

Weekly employee time-card of an organization has three data items: an identification number, the hourly wage rate, and the number of hours worked during a given week. Each employee is paid one and half of the wages for all hours worked over 40 hours. A tax amount of 3.625% of gross wages will be deducted.

Given an identification number, hourly wage rate and number of hours worked, write an algorithm and the subsequent ‘C’ program to display the employee’s number and net pay separated by a tab. Round the net pay of the employee to three decimal places

Input Format

First line contains the identification Number

Next line contains the hourly wage rate

Next line contains the number of Hours worked

Output  Format

Print the Employee number and net pay separated by a space

Solution

#include < stdio.h >
int main()
{
    int n,w,h;
    float s=0;
    scanf("%d %d %d",&n,&w,&h);
    if(h > 40)
    {
        s=(h-40)*(w*1.5);
        h=40;
    }
    s=s+(h*w);
    s=s-(s*0.03625);
    printf("%d %.3f",n,s);
    return(0);
}

Input

INPUT:

n - reg number
w - wages per hour
h - hours worked

Output

OUTPUT:

printf("%d %.3f",n,s);

Processing

if(h > 40)
    {
        s=(h-40)*(w*1.5);
        h=40;
    }
    s=s+(h*w);
    s=s-(s*0.03625);

Pseudocode

BEGIN

Read n,w and h
if(h > 40)
    {
        s=(h-40)*(w*1.5);
        h=40;
    }
    s=s+(h*w);
    s=s-(s*0.03625);
    printf("%d %.3f",n,s);

END

Question 5 (Feet per second)

Given the  time in minutes and seconds, clocked by each runner in an one-mile race, write an algorithm and the subsequent ‘C’ code to compute the speed in feet per second (fps) and speed in meter per second (mps). (1 mile=5280 feet and 1mile= 1609.34 m). Round-off milliseconds values if given. For example, if the completion time of a runner is 3 minutes 52.83 seconds then round it off to 3 minutes and 53 seconds for calculation.

Input Format:

First line contains the minutes taken by the player

Next line contains the seconds taken by the player

Output Format

Speed in feet per second fps

Speed in meter per second mps

All values must be rounded to two decimal places

Solution

#include < stdio.h >
#include < math.h >
int main()
{
    int m;
    float s,t,fps,mps;
    scanf("%d %f",&m,&s);
    t=(m*60)+round(s);
    fps=5280/t;
    mps=1609.34/t;
    printf("%.2f fps\n%.2f mps",fps,mps);
    return(0);
}

Input

INPUT:

m - minutes
s - seconds
math.h

Output

OUTPUT:

printf("%.2f fps\n%.2f mps",fps,mps);

Processing

t=(m*60)+round(s);
fps=5280/t;
mps=1609.34/t;

Pesudocode

BEGIN

Read m and s
t=(m*60)+round(s);
fps=5280/t;
mps=1609.34/t;
printf("%.2f fps\n%.2f mps",fps,mps);

END
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s