March 2020

Implement a class Complex which represents the Complex Number data type. Implement the following operations:

Complex Number Using Operator Overloading


1. Constructor (including a default constructor which creates the complex number 0+0i2. Overloaded operator+ to add two complex numbers.3. Overloaded operator* to multiply two complex numbers.4. Overloaded << and >> to print and read Complex Numbers. 

Problem Solution:

#include<iostream>
using namespace std;
class personal
{
protected:
char name[10];
int roll_no;
public:
void get();
void put();
};
class academic:virtual public personal
{
protected:
char sname[10];
int smarks;
public:
void get();
void put();
};
class professional:virtual public personal
{
protected:
char dname[10];
int dmarks;
public:
void get();
void put();
};
class student:public academic,public professional
{
public:
void input();
void display();
};
void personal::get()
{
cout<<"\nenter name and roll no:";
cin>>name>>roll_no;
}
void personal::put()
{
cout<<"\n"<<name;
cout<<"\t"<<roll_no;
}

void academic::get()
{
cout<<"\nenter sname and smarks:";
cin>>sname>>smarks;
}
void academic::put()
{
cout<<"\t"<<sname;
cout<<"\t"<<smarks;
}
void professional::get()
{
cout<<"\nenter dname and dmarks:";
cin>>dname>>dmarks;
}
void professional::put()
{
cout<<"\t"<<dname;
cout<<"\t"<<dmarks;
}
void student::input()
{
personal::get();
academic::get();
professional::get();
}
void student::display()
{

personal::put();
academic::put();
professional::put();
}

int main()
{

student s[10];
int i,j,n,pos;
char ch;
cout<<"enter number of inputs";
cin>>n;
do
{


cout<<"1.accept 2.display 3.insert 4.delete";
cin>>j;
switch(j)
{
case 1:
for(i=0;i<n;i++)
{
s[i].input();
}
break;
case 2:
cout<<"\nname\troll no\tsname\tsmarks\tdname\tdmarks";
for(i=0;i<n;i++)
{
s[i].display();
}
break;
case 3:
cout<<"\nenter posn";
cin>>pos;
if(pos>=0&&pos<n)
{
for(i=n;i>pos;i--)
s[i]=s[i-1];
s[pos].input();
n++;
}
else
cout<<"\nincorrect posn";
break;
case 4:
cout<<"\nenter pos";
cin>>pos;
if(pos>=0&&pos<n)
{
for(i=pos;i<n;i++)
s[i]=s[i+1];
n--;
}
else
cout<<"incor pos";
}
cout<<"\ndo you want to continue";
cin>>ch;
}
while(ch=='Y'||ch=='y');
}


Write a C++ program create a calculator for an arithmetic operator (+, -, *, /). 


Create a calculator for Arithmetic Operators 


Problem Solution:

#include <iostream>
using namespace std;
class number
{
public : float a,b;
         char ch;                             
         char get();
void display();
float add();
float sub();
float mul();
float div();
number();
number(int m,int n );
number(number&n1);
~number();
};
number::~number()
{
cout<<"\n Constructor Is Destroyed";
}
number::number(int m,int n )
{
a=m;
b=n;
cout<<"\nparameterized const is called";
}
number::number(number &n1)
{
cout<<"\ncopy is called:";
a=n1.a;
b=n1.b;
}
char number:: get()
{
cout<<"\nEnter Any Two Nos.";
cin>>a>>ch>>b;
        return ch;
}
void number:: display()
{
cout<<"\nTwo Nos. are"<<"\n"<<a<<"\n"<<b;
}
float number:: add()
{
return a+b;
}
float number:: sub()
{
return a-b;
}
float number:: mul()
{
return a*b;
}
float number:: div()
{
return a/b;
}
number::number(){a=10 ;b=20;cout<<"\ndefault const is called";}
int main()
{
number n;
n.display();
char ch,op;
number n1(20,30);
n1.display();
number n2(n1);
n2.display();
do
{
ch=n.get();
switch(ch)
{
  case '+':
cout<<"\nAddition Is:"<<n.add();
break;
case '-':
cout<<"\nSubstraction Is:"<<n.sub();
break;
case '*':
cout<<"\nMultiplication Is:"<<n.mul();
break;
case '/':
cout<<"\nDivision Is:"<<n.div();
break;
}
cout<<"\ndo you want to continue (Y)";
cin>>op;
}
while(op=='Y'||op=='y');
}


Software Development Process
• Software development process is carried out in various steps. These steps an basically called as software development phases.
• The system gets developed gradually during each of these phases. For example -after requirement analysis phase, the requirements of the system can be identified and SRS is prepared. After the software design phase, the design of the system on paper gets ready and so on.

Software Development Process & Environment 
• The collection of these phases determine the life cycle of software. These phases are used in various process models such as waterfall model, life cycle model and so on.
• Thus we can define the software development process as

Definition : Software development process is a sequential combination of phases, each having well defined starting and ending points and at each phase there are identifiable deliverables to the next phase.
• During the software development process, the deficiencies of previous stage must be identified and corrected.
• Various phases of software development process are
-Requirement analysis & specification
-Software design and specification
-Implementation
-Verification and validation
-Testing
-Maintenance

Phases of software development process

(1) Requirements Analysis and Specification

The requirements of the system are identified and documented in this phase.
• The requirement gathering and identification tasks are jointly carried out by the users and developers of the system.
. These requirements are then documented in a document which is popularly known as Software Requirement Specification(SRS),
• The SRS does not specify how to meet these requirements in the system.

(2) Software Design and Specification

• The SRS is used during the software design and specification. During this phase,varlous software modules and their interfaces are designed.
• In this phase, the software design document is prepared. This document specifies the functionality of each module, their interfaces and the software architecture used.

(3) Implementation

• Implementation is a phase in which the coding is done in suitable programming language with the help of design document.
• Ideally it should be simply mapping of software design into the corresponding code.
• At the end of this phase, fully implemented and documented system is ready for testing and validation

(4) Verification and Validation

•This phase is for checking the quality of the software system being developed.
•Verification means -" Are we building the product right?" and validation means -
" Are we building the right product?".

(5) Testing

•Testing is a process of finding bugs or errors from the system.
•Testing is done mainly for two things-
i) Module testing 
ii) Integration testing
•Module testing is performed to know whether particular module is working according to its specification or not. While integration testing is to uncover the inter-modular inconsistencies.

(6) Maintenance

• After delivering the software system to the user, there are chances for changes in the system due to some malfunctioning or due to some additional functionality.
•Many times the changes are made in the system to withstand in a new operational envirornment.
•This cost of maintenance is always higher than all other the software development.

Language and Software Development Environment

Definition of Software Development Environment : The software development environment means an integrated set of tools and techniques that are used development of software.
• This environment (actually set of tools) are used in al phases of software development such as-requirements, design, coding testing and so on.
• The ideal scenario for use of environment can be specified as follows -

Step 1: During requirement analysis and specification phase, the environment keeps track of requirements. It helps in identifying incompleteness and inconsistency in requirements. It also provides the facility to validate the requirements.

Step 2: After completion of requirements analysis, the software designers interact with the environment and get the help in creating initial system design. This design is then refined to get final design for the system.

Step 3 : At the implementation (ie. coding) phase, the environment assists the software developer by automating some development steps, by suggesting the reuse of existing design and reuse of components from library. Various tools that are commonly used in this phase are - interactive editors, compilers, interpreters
linker, debuggers and so on.

Step 4: The impletation is further tested in order to find bug. There are various automated testing tools available which help in generating the test cases.

• The software development cenvironment can be commercially provided by the support tools called CASE i.e. Computer Aided Software Engineering.

Evolution of Computers-Brief History

History of computers Gives us the basic information about the technological development trends in computer in the past and its projections in the future.

The Secret History Of Evolution Of (a Brief History) Computer - Computer Architecture

The ancestors of modern age computers were the mechanical
and electromechanical devices. This ancestry can be traced as back as 17th century. when the first machine capable of performing four
mathematical operations, viz., addition, subtraction, division and
multiplication.

Mechanical Computers

Blaise Pascal made the very first attempt towards the automatic computing. He invented a device, which consisted of lots of gears and chains and used to perform repeated additions and subtractions.
This device was called Pascaline. Later many attempts were
made in this direction; we will discuss some details about the
innovation by Charles Babbage, the grandfather of modern
computer. 
He designed two computers.

* The difference engine

It was based on the mathematical principle of finite differences and was used to solve calculations on large number using a formula. It was also used for solving the polynomial and
trigonometric functions.

* The analytical engine by Babbage

It was a general purpose computing device, which could be used for perferming any mathematic operation automatically. It consisted of the following components:
The store : A mechanical memory unit consisting of sets of counter wheels.
The mill : An arithmetic unit, which is capable of performing the four basic arithmetic operations.

Cards: 

There are basically two types of cards:

Types of Cards-
1.Operation Cards
2. Variable Cards

(i) Operation cards
Selects one of the four arithmetic operations by activating the
mill to perform the selected operation.

(ii) Variable cards
Selects the memory location to be used by the, mill for a particular operation (i.c. the source of the operands and the destination of the results).
Output : Could be directed to a printer or a card punch device.

The basic feature of this analytical engine were:
-It was a general purpose programmable machine.
-It had the provision of automatic sequence control, thus enabling programs to alter its sequence of operations.
-The provision of sign checking of result existed.
-Mechanism for advancing or reversing of control card was
permitted thus enabling execution of any desired instruction.
-In other words, Babbage has devised a conditional and
branching instructions.
-The Babbage machine is fundamentally the same as a
moden computer.

The First Generation : Vacuum Tubes
The first electronic computer was constructed using vacuum tubes. The first computer constructed using vacuum tube technology vas ENIAC (Electronic Numerical Integrator and Calculator).
-It was enormous machine weighing about 30 tons.
-It contained more than 18,000 vacuum tubes.
-It consumed 140 kilowatts of power.
-It was a decimal rather than a binary machine.
-It was capable of 5000 additions per second.
-It had memory to hold twenty 10 digit decimal numbers.
-It stored programs and data in separate memories.

EDVAC (Electronic Device Variable Computer)
ENIAC stored program and data in separate memories entering or altering program was a difficult task, EDVAC stores both program and data in the same memory.

Concept of common memory for both program and data
-EDVAC has two kinds of memory : a fast main memory with
a capacity of 1024 and slower secondary memory of 20k words.
-It stored and processed number in binary form to minimize
hardware cost. It processed data bit by bit.
-Prior to execution, a set of instructions forming a program is
placed in the EDVAC main memory. The instructions were then transferred one a time from the main memory to the CPU for execution.
-Each instruction had a well defined structure of the form:
A1,A2,A3,A4,op.
-The meaning :perform the operation op (addition, subtraction, multiplication, etc.) on the contents of main memory locations A1, and A2, and then place the result In main memory location A3,A4 specifies the address of the next instruction to be executed.

The trends, which were encountered during the era of first-generation computers.

-Centralized control in a single CPU; all the operations required a direct intervention of the CPU.
-Use of ferrite-core main memory had started.
-Concept of virtual memory had started.
-Punched cards were used as input.
-Magnetic tapes and magnetic drums were used as secondary
memory.
-Binary code or machine language was used for programming.
-Towards the end due to diffīculties encountered in use of machine language as programming language, the use of symbolic language that is now called assembly language started.
-Assembler, a program that translates assembly language programs to machine language was made.
-Computer was accessible to only one programmer (single user mode).
-Advent of Von Neumann architecture.

The Second Generation: Transistors

-The use of the transistors defines the second generation of
computers.
-Vacuum tubes were replaced by transistors. The transistor is smaller, cheaper and dissipates less heat than a vacuum tube.
-The second-generation characterizes greater speed, larger memory capacity and a smaller size over the first generation.
-Computer hardware and software evolved rapidly after the introduction of the second-generation computers.
-Complex instructions were added to the set of instructions.
-More registers were added to the CPU to facilitate data and
address manipulation.
-Floating point number was introduced to support scientific 
application.
-Input/output operations were added for easy transfer of the
information to and from peripheral devices like printer and
secondary memory
-High level programming languages were introduced.
-Provision of system software with the computer


The Third Generation :Integrated Circuits

This generation is associated with the introduction of Integrated Circuits (ICs) This replaced the discrete electronic circuits used in second generation camputers

ICs allowed a large number of transistors and associated
components to be combined on a tiny piece of silicon wafer.

IC technology initiated a long terms trend towards
(1) Higher speed
(2) Smaller size
(3) Lower hardware cost
(4) Lower power consumption
(5) More reliable circuit

IBM developed the most influential third generation computer, the system/360. The machine becamec a standard for all main frame computers.
-It was based on Von Neumann architecture.
-It had about 200 distinct instruction types
-It had many addressing modes.
-It supported various data types.
-It supported both fixed point and floating point numbers.
-It had 16 general purpose registers.
-The CPU had two major control states
(1) Supervisory state for use by the operating system.
(2) User state for executing application programs.

 Later Generations : VLSI 

VLSI allowed manufactures to fabricate a CPU, main
memory or even all the electronic circuit of a computer on a single
IC that can be mass produced at a very low cost. This resulted in a
new class of machines ranging from portable personal computers to
supercomputers that contain thousands of CPUS. Two most
important impact of VLSI are:
(1) Semiconductor memory
(2) Microprocessors

Programmable Logic Devices (PLDs) Lesson Objectives: In this lesson you will be introduced to some types of Programmable Logic Devices (PLDs): ¾ PROM, PAL, PLA, CPLDs, FPGAs, etc. ¾ How to implement digital circuits using PLAs and PALs. 

Introduction: An IC that contains large numbers of gates, flip-flops, etc. that can be configured by the user to perform different functions is called a Programmable Logic Device (PLD). The internal logic gates and/or connections of PLDs can be changed/configured by a programming process. One of the simplest programming technologies is to use fuses. In the original state of the device, all the fuses are intact. Programming the device involves blowing those fuses along the paths that must be removed in order to obtain the particular configuration of the desired logic function. PLDs are typically built with an array of AND gates (AND-array) and an array of OR gates (OR-array).

Advantages of PLDs: Problems of using standard ICs: Problems of using standard ICs in logic design are that they require hundreds or thousands of these ICs, considerable amount of circuit board space, a great deal of time and cost in inserting, soldering, and testing. Also require keeping a significant inventory of ICs. Advantages of using PLDs: Advantages of using PLDs are less board space, faster, lower power requirements (i.e., smaller power supplies), less costly assembly processes, higher reliability (fewer ICs and circuit connections means easier troubleshooting), and availability of design software. There are three fundamental types of standard PLDs: PROM, PAL, and PLA. A fourth type of PLD, which is discussed later, is the Complex Programmable Logic Device (CPLD), e.g., Field Programmable Gate Array (FPGA). A typical PLD may have hundreds to millions of gates. In order to show the internal logic diagram for such technologies in a concise form, it is necessary to have special symbols for array logic. Figure shows the conventional and array logic symbols for a multiple input AND and a multiple input OR gate.

Three Fundamental Types of PLDs: The three fundamental types of PLDs differ in the placement of programmable connections in the AND-OR arrays. Figure shows the locations of the programmable connections for the three types.

¾ The PROM (Programmable Read Only Memory) has a fixed AND array (constructed as a decoder) and programmable connections for the output OR gates array. The PROM implements Boolean functions in sum-of-minterms form. ¾ The PAL (Programmable Array Logic) device has a programmable AND array and fixed connections for the OR array. ¾ The PLA (Programmable Logic Array) has programmable connections for both AND and OR arrays. So it is the most flexible type of PLD. 

The ROM (Read Only Memory) or PROM (Programmable Read Only Memory): The input lines to the AND array are hard-wired and the output lines to the OR array are programmable. Each AND gate generates one of the possible AND products (i.e., minterms). In the previous lesson, you have learnt how to implement a digital circuit using ROM. 

The PLA (Programmable Logic Array): In PLAs, instead of using a decoder as in PROMs, a number (k) of AND gates is used where k < 2n , (n is the number of inputs). Each of the AND gates can be programmed to generate a product term of the input variables and does not generate all the minterms as in the ROM. The AND and OR gates inside the PLA are initially fabricated with the links (fuses) among them. 

Programmable Logic Device 

The specific Boolean functions are implemented in sum of products form by opening appropriate links and leaving the desired connections. A block diagram of the PLA is shown in the figure. It consists of n inputs, m outputs, and k product terms.  

The product terms constitute a group of k AND gates each of 2n inputs. Links are inserted between all n inputs and their complement values to each of the AND gates. Links are also provided between the outputs of the AND gates and the inputs of the OR gates. Since PLA has m-outputs, the number of OR gates is m. 

The output of each OR gate goes to an XOR gate, where the other input has two sets of links, one connected to logic 0 and other to logic 1. It allows the output function to be generated either in the true form or in the complement form. The output is inverted when the XOR input is connected to 1 (since X ⊕ 1 = X/ ). The output does not change when the XOR input is connected to 0 (since X ⊕ 0 = X). Thus, the total number of programmable links is 2n x k + k x m + 2m. The size of the PLA is specified by the number of inputs (n), the number of product terms (k), and the number of outputs (m), (the number of sum terms is equal to the number of outputs). 

Field Programmable Gate Arrays (FPGAs): 
The FPGA consists of 3 main structures: 
1. Programmable logic structure, 
2. Programmable routing structure, and 
3. Programmable Input/Output (I/O). 

1. Programmable logic structure The programmable logic structure FPGA consists of a 2-dimensional array of configurable logic blocks (CLBs). Each CLB can be configured (programmed) to implement any Boolean function of its input variables. Typically CLBs have between 4-6 input variables. Functions of larger number of variables are implemented using more than one CLB. In addition, each CLB typically contains 1 or 2 FFs to allow implementation of sequential logic. Large designs are partitioned and mapped to a number of CLBs with each CLB configured (programmed) to perform a particular function. These CLBs are then connected together to fully implement the target design. Connecting the CLBs is done using the FPGA programmable routing structure. 

2. Programmable routing structure To allow for flexible interconnection of CLBs, FPGAs have 3 programmable routing resources: 1. Vertical and horizontal routing channels which consist of different length wires that can be connected together if needed. These channel run vertically and horizontally between columns and rows of CLBs as shown in the Figure. 2. Connection boxes, which are a set of programmable links that can connect input and output pins of the CLBs to wires of the vertical or the horizontal routing channels. 3. Switch boxes, located at the intersection of the vertical and horizontal channels. These are a set of programmable links that can connect wire segments in the horizontal and vertical channels.

3. Programmable I/O These are mainly buffers that can be configured either as input buffers, output buffers or input/output buffers. They allow the pins of the FPGA chip to function either as input pins, output pins or input/output pins. 

Random Access Memory

A memory unit is a collection of storage cells together with associated circuits needed to transfer information in and out of the device. 
Memory cells can be accessed for information transfer to or from any desired random location and hence the name randomaccess memory, abbreviated RAM. 
A memory unit stores binary information in groups of bits calledwords. 1 byte = 8 bits 1 word = 2 bytes. 
The communication between a memory and its environment is achieved data input and output lines, through address selection lines, and control lines that specify the direction of transfer. 

Content of amemory 
 Each word in memory is an identification called assigned number, starting from 0 an address, up to 2 k -1, where k is the number of addresslines. 
 The number of words in a memory with one of the letters K=210, M=220, or G=230. 64K = 2 16 2M = 2 21 4G = 2 32

READ ONLY MEMORY (ROM) 

• Computers almost always contain a small amount of read-only memory that holds instructions for starting up the computer.Unlike RAM, ROM cannot be written to. 
• Because data stored in ROM cannot be modified (at least not very quickly or easily), it is mainly used to distribute firmware (software that is very closely tied to specific hardware, and unlikely to require frequent updates). 
• It is non-volatile which means once you turn off the computerthe information is stillthere. 

Title: String Operations

Objectives: 

 To implement different operations on strings like Creating, copying, modifying, concatenating, reversing, Finding substrings, etc.  To simulate the inbuilt string operations function.

String: 
A string is a character array terminated by a null character (\0). In C, the null character can be used to mark the end of a string. A string constant is a series of characters enclosed by double-quotes. The C compiler automatically appends a null character to the array that has been initialized by a string constant. char str[7] = "Hello!";

Substring : 
A string is a substring of the main string if it is a part of the main string. 

Palindrome: 
A string is a palindrome if the reverse of the string is equal to the original string. e.g: nitin 

Different string operations are as follows : 

1) int strlen( const char *str) -- Calculates string length excluding last null character. 

2) char * strcpy( char *dest, const char * src) – Copies string from source to destination 

3) char *strcat(char *dest, const char * src ) – Appends source string at the end of destination and returns pointer to the destination.

4) int strcmp(const char *str1, const char * str2) – Does an unsigned comparison of two strings character by character and returns difference as an integer. If diff = 0 strings are equal If diff < 0 string1 is smaller than string2 If diff > 0 string1 is greater than string2

5) char * strrev( char *str) – Reverses the input string and returns a pointer to the reversed string. 

6) char *strstr( char *str1, char *str2) – Checks for string2 in string1 and returns pointer to location of first occurrence. 

7) String palindrome – Checking if reversed string is same as original string. The strlen() Function 

Strlen() Function-

The strlen() function can be used to measure the length of a string. This function does not count the null character in the last element The syntax for the strlen() function is size_t strlen(const char *s); Here s is a char pointer variable. The return value from the function is the number of bytes. size_t is a data type defined in the string.h header file. The size of the data type depends on the particular computer system. 

String Operations Data Structures in C++


Strcpy() Function-

The strcpy() Function If you want to copy a string from one array to another, you can copy each item of the first array to the corresponding element in the second array, or you can simply call the C function strcpy() to do the job for you. The syntax for the strcpy() function is char *strcpy(char *dest, const char *src); Here the content of the string src is copied to the array referenced by dest. The strcpy() function returns the value of src if it is successful. The header file string.h must be included in your program before the strcpy() function is called. 

Strcat() Function-

The strcat() Function strcat appends a copy of src to the end of dest. The length of the resulting string is strlen(dest) + strlen(src). The syntax for the strcat() function is char *strcat(char *dest, const char *src); strcat returns a pointer to the concatenated strings. 

Strrev() Function-

The strrev() Function Reverses all characters in a string (except for the terminating null) The syntax for the strrev() function is char *strrev(char *s); For example, it would change string\0 to gnirts\0 strrev returns a pointer to the reversed string. 

Strcmp() Function-

The strcmp() Function Compares two strings. The string comparison starts with the first character in each string and continues with subsequent characters until the corresponding characters differ or until the end of the strings is reached. The syntax for the strcmp() function is int strcmp(const char *s1, const char*s2); This function returns an int value that is < 0 if s1 < s2 == 0 if s1 == s2 > 0 if s1 > s2 

Strlwr() Function-

The strlwr() Function Converts uppercase letters (A to Z) in string s to lowercase (a to z). The syntax for the strlwr() function is char *strlwr(char *s); No other characters are changed. Return Value is a pointer to the string s. 

Strupr() Function-

The strupr() Function Converts lowercase letters (a to z) in string s to uppercase (A to Z). The syntax for the strupr() function is char *strupr(char *s); No other characters are changed. Return Value is a pointer to the string s. 

Strstr() Function-

The Strstr() Function Finds the first occurrence of a substring in another string The syntax for the strupr() function is char *strstr(const char *s1, const char *s2); strstr scans s1 for the first occurrence of the substring s2. Return Value: On success, strstr returns a pointer to the element in s1 where s2 begins (points to s2 in s1). On error (if s2 does not occur in s1), strstr returns null.

Top 10 Expected Questions Based On String Operations Data Structures Practical Approach: 

Q1. What is a string? How do you know its length? 

Q2. What are the main differences between a string constant and a character constant? 

Q3. Does the gets() function save the newline character from the standard input stream? 

Q4. What types of data can the scanf() function read? 

Q5. What are the left and right values (lvalue & rvalue)? 

Q6. How can you obtain the address of a variable? 

Q7. What is the concept of indirection in terms of using pointers? 

Q8. Can a null pointer point to valid data? 

Q9. What is the main difference between using scanf & gets for accepting strings ? 

Q10. How do you reference an array by using a pointer? 


Design Experiments: 


1. Simulate the following string library functions with pointers to arrays. 

char *strncpy(s,ct,n) Copies at most n characters of string ct to s Returns s. Pads with '\0's if t has fewer than n characters. 

char *strncat(s,ct,n) Concatenates at most n characters of string ct to end of string s; terminates s with '\0'. Returns s. 

int *strncmp(cs,ct,n) Compares at most n characters of string cs to string ct. Returns < 0 if cs < ct 0 if cs= =ct or > 0 if cs > ct 

char *strchr(cs,c) Returns a pointer to the first occurrence of c in cs or NULL if not present. 

char *strrchr(cs,c) Returns a pointer to the last occurrence of c in cs or NULL if not present

2. Simulate the following string library functions with pointers to arrays

size_t strspn(cs,ct) Returns length of prefix of cs consisting of characters in ct.

size_t strcspn(cs,ct) Returns length of prefix of cs consisting of characters not in ct. 

char *strpbrk(cs,ct) Returns pointer to first occurrence in string cs of any character of string ct, or NULL if none present.

char *strstr(cs,ct) Returns pointer to first occurrence of string ct in cs, or NULL if not present. size_t strlen(cs) Returns the length of string cs.  

char *strerror(n) Returns pointer to implementation-defined string corresponding to error n. 

char *strtok(s,ct) strtok searches s for tokens delimited by characters from ct, NULL if none are found. 

Implement above  by dynamically allocating memory for string and perform the various operations on strings with pointers to arrays.

Thus the String Handling Functions (StringCopy, StringLength, StringCompare, StringReverse, StringConcat, SubString) have been Successfully Learned.

Disclaimer: This Site is Protected By Educationworldsystem. Copying of Content Is Strictly Prohibited. 
We Wish to Express Our Profound Thanks to all Those who helped in making this Website a reality

Write a C++ program create a calculator for an arithmetic operator (+, -, *, /). The program should take two operands from user and performs the operation on those two operands depending upon the operator entered by user. Use a switch statement to select the operation. Finally, display the result. Some sample interaction with the program might look like this: Enter first number, operator, second number: 10 / 3 Answer = 3.333333 Do another (y/n)? y Enter first number, operator, second number: 12 + 100 Answer = 112 Do another (y/n)? 










C++ Programme To Make Calculator For Arithmetic Operators 

SOL:

#include <iostream>
using namespace std;
class number
{
public : float a,b;
         char ch;                         
         char get();
 void display();
 float add();
 float sub();
 float mul();
 float div();
 number();
 number(int m,int n );
 number(number&n1);
 ~number();
};
number::~number()
{
cout<<"\n Constructor Is Destroyed";
}
number::number(int m,int n )
{
a=m;
b=n;
cout<<"\nparameterized const is called";
}
number::number(number &n1)
{
cout<<"\ncopy is called:";
a=n1.a;
b=n1.b;
}
char number:: get()
{
cout<<"\nEnter Any Two Nos.";
cin>>a>>ch>>b;
        return ch;
}
void number:: display()
{
cout<<"\nTwo Nos. are"<<"\n"<<a<<"\n"<<b;
}
float number:: add()
{
return a+b;
}
float number:: sub()
{
return a-b;
}
float number:: mul()
{
return a*b;
}
float number:: div()
{
return a/b;
}
number::number(){a=10 ;b=20;cout<<"\ndefault const is called";}
int main()
{
number n;
n.display();
char ch,op;
number n1(20,30);
n1.display();
number n2(n1);
n2.display();
do
{
ch=n.get();
switch(ch)
{
  case '+':
cout<<"\nAddition Is:"<<n.add();
break;
case '-':
cout<<"\nSubstraction Is:"<<n.sub();
break;
case '*':
cout<<"\nMultiplication Is:"<<n.mul();
break;
case '/':
cout<<"\nDivision Is:"<<n.div();
break;
}
cout<<"\ndo you want to continue (Y)";
cin>>op;
}
while(op=='Y'||op=='y');
}
Expected Output: default const is called
Two Nos. are
10
20
parameterized const is called
Two Nos. are
20
30
copy is called:
Two Nos. are
20
30
Enter Any Two Nos.10
50
do you want to continue (Y)

Object-Oriented Programming

PROGRAMMING TECHNIQUES

•   Unstructured programming

•   Procedural programming

•   Modular programming

•   Object-oriented programming

•   Generic programming         

    UNSTRUCTURED PROGRAMMING

•   Only one Program i.e. main Program

•   All the sequences of commands or statements in one programs called the main Program

•   E.g. Fortran, assembly language, old Basic

   MODULAR PROGRAMMING

•   Procedures with some common functionality are grouped together into separate modules
•   Program is categorized into several smaller modules
•   Each module can have its own data

   Procedural Oriented Language

• Conventional programming, using a high-level language such as COBOL, FORTRAN, and C are commonly-known as Procedure oriented language (POP).
• In POP numbers of functions are written to accomplish the tasks

Problem Statement:

In Second-year Computer Engineering class of M students, set A of students play cricket and set B of students play badminton. Write C/C++ program to find and display. Set of students who play either cricket or badminton or both ii. Set of students who play both cricket and badminton iii. Set of students who play only cricket iv. Set of students who play only badminton v. Number of students who play neither cricket nor badminton (Note- While realizing the set duplicate entries are to avoided)


Problem Solution:


#include<iostream>
using namespace std;
class M
{
int a[10],b[10],c[20],d[20],u[20];
int m,n,i,j,k,p,q,flag,e;
public:
       void get();
       void intersection();
       void Union();
       void only_A();
       void only_B();
       void neither();
};
void M::get()
{
cout<<"enter the total number of students :"<<"\n";
cin>>q;
cout<<"Enter the roll no of all students :"<<"\n";
        for(p=0;p<q;p++)
  {
    cin>>u[p];
  }
  cout<<"Enter total no of students playing cricket: "<<"\n";
  cin>>m;
  cout<<"Enter roll no of students playing cricket: "<<"\n";
  for(i=0;i<m;i++)
  {
    cin>>a[i];
  }
  cout<<"\nEnter total no of students playing badminton: "<<"\n";
  cin>>n;
  cout<<"Enter roll no of students playing badminton: "<<"\n";
  for(i=0;i<n;i++)
  {
    cin>>b[i];
  }
cout<<"\n\nUniversal = {";
  for(p=0;p<q;p++)
  {
  cout<<" "<<u[p];
  if(p!=q-1)
{
cout<<",";
}
  else
{
cout<<" }\n";
}
  }
cout<<"\n\nA = {";
  for(i=0;i<m;i++)
  {
  cout<<" "<<a[i];
  if(i!=m-1)
{
cout<<",";
}
  else
{
cout<<" }\n";
}
  }
cout<<"\nB= {";
  for(i=0;i<n;i++)
  {
  cout<<" "<<b[i];
  if(i!=n-1)
{
cout<<",";
}
  else
{
cout<<" }\n";
}
  }
}

void M::intersection()
{
k=0;
for(i=0;i<m;i++)
  {
  for(j=0;j<n;j++)
    {
    if(a[i]==b[j])
      {
      c[k]=a[i];
k++;
      }
    }
  }
  cout<<"\nSet of students who play both cricket and badminton = {";
  for(i=0;i<k;i++)
  {
    cout<<" "<<c[i];
  if(i!=k-1)
  {
  cout<<",";
  }
  }
  cout<<" }\n\n";
}
void M::Union()
{
  k=0;
  for(i=0;i<m;i++)
  {
    flag=0;
    for(j=0;j<n;j++)
    {
    if(a[i]==b[j])
      {
flag=1;
}
    }
    if(flag==0)
{
c[k]=a[i];
k++;
}
  }
  for(i=0;i<n;i++)
  {
  c[k]=b[i];
k++;
  }
  cout<<"\nSet of students who play either cricket or badminton or both= {";
  for(i=0;i<k;i++)
  {
  cout<<" "<<c[i];
  if(i!=k-1)
{
cout<<",";
}
  }
  cout<<" }\n\n";
}
void M::only_A()
{
k=0;
  for(i=0;i<m;i++)
  {
    flag=0;
    for(j=0;j<n;j++)
    {
      if(a[i]==b[j])
        {
flag=1;
}
    }
  if(flag==0)
{
c[k]=a[i];
k++;
}
  }
  cout<<"\nSet of students who play only cricket= {";
  for(i=0;i<k;i++)
  {
  cout<<" "<<c[i];
  if(i!=k-1)
{
cout<<",";
}
  }
  cout<<" }\n\n";
}
void M::only_B()
{
  k=0;
  for(i=0;i<n;i++)
  {
    flag=0;
    for(j=0;j<m;j++)
    {
      if(a[j]==b[i])
       {
flag=1;
}
    }
    if(flag==0)
{
c[k]=b[i];
k++;
}
}
cout<<"\nSet of students who play only badminton  ={";
  for(i=0;i<k;i++)
  {
  cout<<" "<<c[i];
  if(i!=k-1)
{
cout<<",";
}
  }
  cout<<" }\n\n";
}
       void M::neither()
{
       
  k=0;
  for(i=0;i<m;i++)
  {
    flag=0;
    for(j=0;j<n;j++)
    {
    if(a[i]==b[j])
      {
flag=1;
}
    }
    if(flag==0)
{
c[k]=a[i];
k++;
}
  }
  for(i=0;i<n;i++)
  {
  c[k]=b[i];
k++;
  }
 
e=0;
for(p=0;p<q;p++)
{
flag=0;
  for(i=0;i<k;i++)
{
if(u[p]==c[i])
{
flag=1;
}
}
if(flag==0)
{
d[e]=u[p];
e++;
}
}
cout<<"\nSet of students who play neither cricket nor badminton= {";
  for(p=0;p<e;p++)
  {
  cout<<" "<<d[p];
  if(p!=e-1)
{
cout<<",";
}
  }
  cout<<" }\n\n";
int count=0;
for(p=0;p<e;p++)
{
count++;
}
cout<<"Number of students who play neither cricket nor badminton="<<count<<"\n";
}

int main()
{
 M s; int ch;
 char r,y;
do
 {
 cout<<" \n1. Intersection\n 2. Union\n 3. Only A\n 4. Only B\n 5.Neither\n";
 cout<<"\n\nEnter the your choice: ";
 cin>>ch;

 s.get();
 switch(ch)
 {
  case 1:
 s.intersection();
break;
  case 2:
 s.Union();
break;
  case 3:
s.only_A();
break;
  case 4:
s.only_B();
break;
 case 5:
s.neither();
break;
  default:
 cout<<"\nInvalid Data.\n";
 }
 cout<<"do you want to continue press 'y':"<<"\n";
cin>>r;
}
while(r=='y');
return 0;
}

OUTPUT:


 1. Intersection
 2. Union
 3. Only A
 4. Only B
 5.Neither


Enter the your choice: 1
enter the total number of students :
3
Enter the roll no of all students :
40
50
60
Enter total no of students playing cricket:
2
Enter roll no of students playing cricket:
40
60

Enter total no of students playing badminton:
1
Enter roll no of students playing badminton:
50


Universal = { 40, 50, 60 }


A = { 40, 60 }

B= { 50 }

Set of students who play both cricket and badminton = { }

do you want to continue press 'y':Y/N


Disclaimer: These codes are compiled and executed in Dev c/c++ You are requested to run this code in your compiler before using this program to see the expected output

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget