Saturday, March 31, 2018

Recursive reverse (Id-1250)

Just for Practice 1 Additional [3-Jan-2018 to 10-Apr-2018]

Program ID- 1250

Given a string, write a recursive routine to reverse it. For example, given the string ‘and, the reversal of the string is ‘dna’.
Input Format

A string

Output Format

Reverse of the string

Code: C

#include<stdio.h>
#include<string.h>
int main()
{
    int i;
    char str[100];
    scanf("%s",&str);
    for(i=strlen(str)-1;i>=0;i--)
    {
        printf("%c",str[i]);
    }
}

NOTE: The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

Customer discount

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID

Design an OOP model and implement it using C++ program. Refer the declaration of classes and application program to do the design. The program must get the details, compute bill amount and print details both for ordinary and preferred customers. For example, if a preferred customer makes three purchases of amounts 3000, 7000, 8000 then the amount to be paid for each bill is 3000, 6860 and 7760 and the total amount to be paid is 17620

Code: C++



NOTE: The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

Count Words in Tweets (Id-1531)

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID- 1531

Given a word ‘w’and a set of tweets in a file named as tweets.txt, write a C++ program to count the number of words in the file. Assume that the program need not bother about case of the words as the input takes care of the same.

Input Format

Word to be searched
Tweets in file

Output Format

Count of the words

Code: C++

#include<fstream>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    fstream f;
    char s[100];
    cin>>s;
    char d;
    f.open("tweets.txt",ios::in);
    int c=0;
    int count=0;
    while(!f.eof())
    {
        f.get(d);
        if(d==s[c])
        {
            c++;
        }
        else
        {
            c=0;
        }
        if(c==strlen(s))
        {
            count++;
            c=0;
        }
    }
    cout<<count;
}

NOTE: The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

Names that Do Begin with Vowel – Descending Order (Id-2781)

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID- 2781

Given a set of names, design an algorithm and write a C++ code to form a sorted list, in the descending order of names that do begin with a vowel.

Code: C++



NOTE: The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

Sort Data in File (Id-1532)

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID- 1532

Given a file with a set of numbers in a file, write a C++ program to sort the numbers and print them.

Code: C++

#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
main() {
    int k;
    vector<int> m;
    ifstream f;
    char n[20];
    cin>>n;
    f.open(n);
    while(!f.eof()) {
        f>>k;
        m.push_back(k);
    }
    sort(m.begin(),m.end());
    for(vector<int>::iterator i=m.begin(); i!=m.end(); i++)
        cout<<*i<<endl;
}

NOTE: The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

Chess, Carrom and Scrabble Players (Id-1145)

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID- 1145

Each student in a class of ‘n’ plays at least one indoor game chess, carrom and scrabble. Given three list of names of students who play chess, scrabble and carrom, develop an algorithm and write a C++ code to find the students who can
(i) Play chess and carrom
(ii) Chess, carrom but not scrabble
Understand the template code and implement the member functions of the class
Input Format
Number of students who play chess
Name of student1 who plays chess
Name of student2 who plays chess
Name of student-n who plays scrabble

Number of students who play scrabble
Name of student1 who plays scrabble
Name of student2 who plays scrabble
Name of student-n who plays scrabble
Number of students who play carrom
Name of student1 who plays carrom
Name of student2 who plays carrom
Name of student-n who plays carrom
Output Format
Name of students who play chess and carrom. order the names as given in the chess input list . separate names by a comma Name of students who play chess and carrom but not scrabble. Order the names as given in the chess input list. separate names by a comma
Boundary Conditions
Number of students in class will not be more than 30
Length of name of students in class will not be more than 20
Assume that none of the set will become empty

Code: C++


NOTE: The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

Vector of Characters (Id-1498)

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID- 1498

Design a class charVector that has a character vector as data member. Provide member functions in the class to createVector, duplicateVector, duplicateRevVector and print. Functions shall be defined as follows: initializeVector – read a string and create a vector of characters duplicateVector – Add the content of the vector once at the end. For example if the content of charVector is “bat” then after the function is called the content must “batbat” duplicateRevVector – Add the content of the vector in reverse at the end. For example if the content of charVector is “bat” then after the function is called the content must “battab” print – Print content of vector, use iterators for traversal Use the vector class defined in STL for the implementation. Use [] operator in functions duplicateVector, duplicateRevVector and use iterator in print and initializeVector functions.

CODES: C++




The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

Friday, March 30, 2018

Cyclic Right Shift of Elements (Id-1243)

Just for Practice 1 Additional [3-Jan-2018 to 10-Apr-2018]



Program ID- 1243

Given a set of elements stored in an array and a number ‘m’, design an Algorithm and write the subsequent C program to perform cyclic right shift of the array by ‘m’ places. For example, if the elements are 12, 13, 16, 7, 10 and m =2 then the resultant set will be 7, 10, 12, 13, 16.

Input Format:

Number of elements in the set: ‘n’

element-1

element-2



element-n

value of ‘m’

Output Format:

Elements in the set after right shift by ‘m’ places.

Code
Please comment down if the code worked for you, also comment if you have other working codes


NOTE:The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

Second Smallest Number (Id-1242)

Just for Practice 1 Additional [3-Jan-2018 to 10-Apr-2018]

CSE1002 Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]
Program ID- 1242
Given a set of elements, design an Algorithm and write the subsequent C program to determine the second smallest number in that set.
Input Format

Number of elements in ‘n’

element-1

element-2



element-n

Output Format

Second smallest element in the set
Code: C
The Below Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    scanf("%d",&n);
    int arr[n],i,j,k;
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(arr[i]>arr[j])
            {
                k=arr[j];
                arr[j]=arr[i];
                arr[i]=k;
            }
        }
    }
    printf("%d",arr[1]);
}