Thursday, 9 February 2017

PPS 3

Tender scrutiny

Question-A government organization received tenders from ‘n’ vendors for their campus renovation work. It has to determine and select the vendor who had quoted the least amount for this renovation work. Given the registration number, address and amount quoted by vendor, design an algorithm and write a C++ code to print the details of vendor for whom the tender will be given. Write a function that returns the details of vendor by reference concept.
Input Format:
Number of tenders received
Registration number of vendor1
Address of vendor1
Amount quoted by vendor1
Registration number of vendor2
Address of vendor2
Amount quoted by vendor2
………
………….
Registration number of vendor n
Address of vendor n
Amount quoted by vendor n
Output Format:
Print the registration number of vendor who won the tender
Print address of vendor who won the tender
Boundary Conditions:
Number of Tender >1

c++ code-


#include<iostream>
#include<string.h>
using namespace std;
main()
{
    int n,i,j,f;
    unsigned long long int max;
    cin>>n;
    int a[n],b[n];
    char s[100][100];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>s[i];
        cin>>b[i];
    }
    max=1000000;
    i=0;
    while(i!=n)
    {
        if (b[i]<max)
        {max=b[i];
        f=i;}
        i++;
    }
cout<<a[f]<<"\n";
cout<<s[f];
}

INPUT-

enter the number of tender and use a for loop to enter the registration number ,address and the amount
for(i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>s[i];
        cin>>b[i];
    }


PROCESSING-

max=1000000;
    i=0;
    while(i!=n)
    {
        if (b[i]<max)
        {max=b[i];
        f=i;}
        i++;
    }


OUTPUT-

print the registration number of the vendor who took the least money and the address.

PSEUDO CODE-

start
step1-enter the number of vendors and use a for loop to take in the details like registration number ,address and the amount.
step2- define a random variable with a very large quantity(here max).
step3-use a while loop to check is the entered amount is smaller than all the amount entered.
step4-assign another value  ' f ' for the index of the string which has taken least amount.
step5-print the minimum amount taken and  the address of the vendor.
stop  



AUTOMATIC VENDING MACHINE-

An automatic vending machine has many snack items arranged in its shelves. Each item has an item code and a cost. A user can enter the amount and key-in the item code. If the itemcode matches an entry in the item list and amount entered by user is less than cost of the item, then the item will be dispensed. Develop an algorithm and write a C++ code to print name of the item if the amount entered is greater than the cost of the item and item code is valid. If the amount is less than the cost of the item then throw a double exception, if the item code entered is wrong then throw a integer exception and when the item entered is not in stock throw a string exception. Print appropriate messages such as “Insufficient amount”, “Wrong item code” or “Less stock”.

Input Format:

Enter the number of items in the vending machine

Itemcode-1

Cost of item1

stock in hand item1

Itemcode-2

Cost of item2

stock in hand item2


Itemcode-n

Cost of item1

stock in hand item3

Item code entered by user

Cost entered by user

Output Format:

Print either item name or “Insufficient amount” or “Wrong item code” or “Less Stock”

Boundary Conditions:

Number of Item  >1

C++ CODE-

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
main()
{
    int n,i,m,p,z=0,f;
    cin>>n;
    int a[100],b[100],c[100];
    for(i=0;i<n;i++)
    {
        cin>>a[i];>>b[i]>>c[i];
    }
    cin>>m>>p;
    for(i=0;i<n;i++)
    {
        if (m==a[i])
        {
            z=i;
            f=1;
            break;}
            else{f=0;}
    }
    if(f==1)
    {
    if (c[z]>=1)
    {
        if (p>b[z])
        {
            cout<<a[z];
        }
        else{cout<<"Insufficient amount";}
    }else{cout<<"Less stock";}
    }

    if (f==0)
        cout<<"Wrong item code";
}


input-

enter the number of items in a vending machine
use a for loop to enter the items
enter the item code.
enter the amount of item.
enter the stock.

output-

Print either item name or “Insufficient amount” or “Wrong item code” or “Less Stock”

processing-

start
step1-enter the number of items in the vending machine.
step2-use a for loop to enter the item code ,cost and stock and store them in 3 different array.
step3-take 2 more inputs from the user i.e. the item code and the cost in hand.
step4-use a for loop to find if the item code entered by the person is available or not.
step5-use if condition to make sure that the stock in hand is greater than 1 and the money is enough to buy the item.
step6-if these condition are not sufficed then use else to print the required statement.
stop

GPT4ALL - A new LLaMa (Large Language Model)

posted 29th March, 2023 - 11:50, GPT4ALL launched 1 hr ago  What if we use AI generated prompt and response to train another AI - Exactly th...