BCSL-032 ASSIGNMENT SOLUTION (2020-21)

If you have any queries please leave a message here
Your Message
×


In this ASSIGNMENT all the below PROGRAMMINGS are written and run in Turbo Dev-C++ 5.11


Q1. a) Write a C++ program to display the table of a given number. Use appropriate formatting to display the table.

Answer : -

#include<iostream>
using namespace std;

class Table
{
public:
void GenerateTable(int n);
};

void Table::GenerateTable(int n)
{
int i;
for(i=1;i<=10;i++)
{
cout << endl;
cout << i << " * " << n << " = " << (i*n);
}
}

int main()
{
int number;
cout << "Enter the Number : ";
cin >> number;
Table ob1;
ob1.GenerateTable(number);
return 0;
}

Output :
Enter the Number : 5
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50




Q1. b) Write C++ program to demonstrate use of followings :
(i) ::
(ii) :?
(iii) sizeof( )

Answer : -

#include<iostream>
using namespace std;

class NumberCheck
{
public:
void OddEvenCheck(int n);
};

/* To define a Function outside of a Class using :: (Scope Resolution Operator) */
void NumberCheck::OddEvenCheck(int n)
{
cout << endl;
/* Determine Odd or Even using ?: (Ternary Operator) */
(n%2 == 0)? cout << "Even Number" : cout << "Odd Number";
}

int main()
{
int number;
cout << "Enter the Number : ";
cin >> number;
NumberCheck ob1;
ob1.OddEvenCheck(number);
/* Returns the size, in bytes, of the given expression or type */
cout << endl << sizeof(number);
return 0;
}

Output :
Enter the Number : 16
Even Number
2




Q1. c) Write a C++ program to create class named Book. Define appropriate constructors ( using concept of overloading) to create differ objects. Define methods for displaying book details including book’s author name, publisher, price of book. Make necessary assumptions wherever required.

Answer : -

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

class Book
{
private:
char book_title[100];
char book_author[50];
char book_publisher[100];
float book_price;

public:
/* Default Constructor */
Book()
{
strcpy(book_title, "-BLANK-");
strcpy(book_author, "-BLANK-");
strcpy(book_publisher, "-BLANK-");
book_price = 0.0;
}

/* Parameterized Constructor */
Book(char title[], char author[], char publisher[], float price)
{
strcpy(book_title, title);
strcpy(book_author, author);
strcpy(book_publisher, publisher);
book_price = price;
}

/* Display Book Details */
void Display()
{
cout << endl << "TITLE - " << book_title;
cout << endl << "AUTHOR - " << book_author;
cout << endl << "PUBLISHER - " << book_publisher;
cout << endl << "PRICE - " << book_price;
}
};

int main()
{
char b_title[100], b_author[50], b_publisher[100];
float b_price;
cout << "Enter the Book Title : ";
gets(b_title);
cout << "Enter the Author Name : ";
gets(b_author);
cout << "Enter the Publisher Name : ";
gets(b_publisher);
cout << "Enter the Book Price : ";
cin >> b_price;
/* Create Object using Defailt Constructor */
Book ob1;
/* Create Object using Parameterized Constructor */
Book ob2(b_title, b_author, b_publisher, b_price);
ob2.Display();
return 0;
}

Output :
Enter the Book Title : Learning C++ : A Hands-On Approach
Enter the Author Name : Eric Nagler
Enter the Publisher Name : Jaico Publishing House
Enter the Book Price : 1680.95

TITLE - Learning C++ : A Hands-On Approach
AUTHOR - Eric Nagler
PUBLISHER - Jaico Publishing House
PRICE - 1680.95




Q2. a) Write C++ program for concatenation of two strings using ‘+’ operator overloading. Make necessary assumptions wherever required.

Answer : -

#include<iostream>
#include<string.h>
using namespace std;

class StringConcatenation
{
private:
char string[100];

public:
StringConcatenation(char s[])
{
strcpy(string, s);
}

/* Overloading + Operator */
void operator +(StringConcatenation obj)
{
strcat(string, obj.string);
cout << string;
}
};

int main()
{
StringConcatenation ob1("Debabrata "), ob2("Panchadhyay");
ob1 + ob2;
return 0;
}

Output :
Debabrata Panchadhyay




Q2. b) Write a C++ program to demonstrate exception handling. This program takes marks of ten students in a subject as input and store it in an array. Make provisions so that if marks entered as input is less than 0 or greater than 100 then message “Invalid Input” is displayed and program terminate normally.

Answer : -

#include<iostream>
using namespace std;

int main ()
{
int array[10], i;
try
{
for(i=0;i<10;i++)
{
cout << "Enter the Marks : ";
cin >> array[i];
if( array[i] < 0 || array[i] > 100 )
{
throw "Invalid Input !";
}
}
}
catch(const char* error)
{
cerr << endl << error;
}
return 0;
}

Output :
Enter the Marks : 10
Enter the Marks : 20
Enter the Marks : 30
Enter the Marks : 200
Invalid Input !



ABOUT US

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.


MORE TOPIC


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us