MENU











Saturday, 30 November 2013

OOPS ASSIGNMENT-2

OOPS ASSIGNMENT-2

1)What is a problem ? Thinking about a problem

Problem:
 Writing a program starts with a problem.



Understanding that problem is key to a good program.
After all, a program that solves the wrong problem is
likely to be of little use to you,however elegant it may be.
 What we want is a program that simply and cleanly
solves the problem we decided to solve.

A program that
 Illustrates design and programming techniques
Gives us a chance to explore the kinds of decisions that a 
programmer must make and the considerations that go into such decisions
Doesn't require too many new programming language constructs
Is complicated enough to require thought about its design
Allows for many variations in its solution
Solves an easily understood problem
Solves a problem that's worth solving
Has a solution that is small enough to completely present and completely comprehend   

Thinking about the problem:
So how do we start? Basically, think a
bit about the problem and how to solve it.
 First think about what the program should do and how you'd like to interact with it.
Later, you can think about how the program could be written to do that.
Try writing down a brief sketch of an idea for a solution, and see what's wrong with that first idea. 
 Maybe discuss the problem and how to solve it with a friend.
Trying to explain something to a friend is a marvelous way of figuring out what's  wrong with ideas,
 even better than writing them down; paper (or a computer) doesn't talk back at you and challenge your assumptions .
 Ideally, design isn't a lonely activity.
Unfortunately, there isn't a general strategy for problem solving that works for all people and all problems. 
Adopt a more than usually skeptical attitude.
 

 Stages of development:
Here is a bit of terminology for program development. 
As you work all a problem you repeatedly go through these stages:
Analysis:
 Figure out what should be done and write a description of your
(current) understanding of that. Such a description is called a set of requirements
or a specification. We will not go into details about how such requirements are developed and written down.
 'That's beyond the scope of this book, but it becomes increasingly important as the size of problems increases.
Design: 
   Create an overall structure for the system, deciding which parts
the implementation should have and how those parts should communicate.
As part of the design consider which tools - such as libraries – can help you Structure the program.
Implementation:
 Write the code, debug it, and test that it actually does what it
is supposed to do.
  


2)Write a program to implement simple caluculator ?

#include <iostream>
using namespace std;
int main()
{
    float num1,num2;
    char ch,t;
    cout<<"Enter the expression (a+b or a-b or a*b ..........)\n";
    cin>>num1>>ch>>num2;
    
    switch(ch)
    {
        case '+' :cout<<num1<<ch<<num2<<"="<<num1+num2<<endl;
                  break;
        case '-' :cout<<num1<<ch<<num2<<"="<<num1-num2<<endl;
                  break;      
        case '*' :cout<<num1<<ch<<num2<<"="<<num1*num2<<endl;
                  break; 
        case '/' :cout<<num1<<ch<<num2<<"="<<num1/num2<<endl;
                  break;
       
    }
    return 0;
}
output:
Enter the expression (a+b or a-b or a*b ..........)
5+2
5+2=7

Enter the expression (a+b or a-b or a*b ..........)
5-2
5-2=3

Enter the expression (a+b or a-b or a*b ..........)
7*10
7*10=70
Enter the expression (a+b or a-b or a*b ..........)
5/2
5/2=2.5



3)Describe briefly about completing a problem ?

loading progress:

No comments:

Post a Comment