Sie sind auf Seite 1von 2

University of Sharjah

Department of Computer Science

1411113: Programming for Engineers


Summer 2011- 2012
HW #1 Due on June 20 t h , 2012

Name:

ID:

Objectives
After completing this assignment, you will be able to:

Analyze problems and write the steps necessary to solve the problem.
Declare variables and use them.
Input and output data.
Use different arithmetic operators.
Solve problems and write a complete algorithm.
Implement complete C++ programs and execute them.

HW Exc.

2.5

2.5

TOTAL:

Mark

Write an algorithm for each of the following problems


Exercise 1: Write a program that inputs an integer and test if the integer is odd or even.

Exercise 2: Write a program that inputs a five digits positive integer and test whether that
integer is a palindrome or not. A palindrome integer is an integer that is symmetric around
its center. The integers 52825, 81318, 12321 are palindromes, while the integer 52823 is
not.

Exercise 3: The following program generates a menu with 3 options (and a default) and
prompts the user to choose one option. Based on the users choice the program carry out
the required action. The menu is coded using nested if else statements. Modify the
code to use the switch statement instead of the if else statements.
#include<iostream>
using namespace std;
int main( )
{
float balance= 23500;
int option, amount;
cout << "1: Withdrawal\n2: Deposit"<< endl;
cout<<"Please enter you selection ( 1, or 2): ";
cin>>option;
cout << "Your balance is " << balance << endl;
if(option == 1)
{
cout<<"Enter amount to withdraw: ";
cin>> amount;
balance= balance - amount;
}
else if(option == 2)
{
cout<<"Enter amount to deposit: ";
cin>> amount;
balance= balance + amount;
}
else
cout << "Wrong value of the option!" << endl;
cout << "Your balance is " << balance << endl;
return 0;
}
Sample input / output:

Das könnte Ihnen auch gefallen