0% found this document useful (0 votes)
527 views

PF Assignment One

This document provides instructions for Assignment 1, which is due on October 9, 2010 at 11:59pm. It includes tasks involving number conversion between binary and decimal, writing C++ programs using cases, loops, and functions, as well as developing an algorithm in pseudocode. Students are instructed to submit their work electronically by the due date as zip files containing both written work and source code files. Late submissions will be penalized.

Uploaded by

hamida_mangal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
527 views

PF Assignment One

This document provides instructions for Assignment 1, which is due on October 9, 2010 at 11:59pm. It includes tasks involving number conversion between binary and decimal, writing C++ programs using cases, loops, and functions, as well as developing an algorithm in pseudocode. Students are instructed to submit their work electronically by the due date as zip files containing both written work and source code files. Late submissions will be penalized.

Uploaded by

hamida_mangal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT ONE 10 marks

Due Friday 10/9/2010 at 11.59pm


available since 26/07, last updated 26/07

Number Conversion (2 marks)

Convert each of the following binary numerals to base 10:

512 256 128 64 32 16 8 4 2 1


1 1 1 1 1 1 1 1 1 1
512+ 256+ 128+ 64+ 32+ 16+ 8+ 4+ 2+ 1+
i. 1111111111(10) =1023

Convert each of the following binary numerals to base 10:

32 16 8 4 2 1
1 0 1 1 0 1
32 0 8 4 0 1
i. 101101(10) = 45

Convert each of the following decimal numerals to binary: 77

77 DECEIMAL NUMBER IN BINARY IS = 1001101

302 DECEIMAL NUMBER IN BINARY IS = 100101110

2|77 1 2| 302 0

2|38 0 2| 151 1

2|19 1 2 | 75 1

2| 9 1 2| 37 1

2| 4 0 2| 18 0

2| 2 0 2| 9 1

2|1 1 2| 4 0

0 2| 2 0

2| 1 1
0

1. Convert base ten number -21 to its equivalent two's complement in 8 bit
(single byte) format. +-21= 10101 -01011

2| 21 1

2| 10 0

2| 5 1

2| 2 0

2| 1 1

2. Convert 11110110 in two's complement representation (in 8 bits) to a base ten


integer.

128 64 32 16 8 4 2 1
1 1 1 1 0 1 1 0
128+ 64+ 32+ 16+ 0 4+ 2+ 0
11110110 = 246

Coding Simple C++ Programs (6


marks)
WRITE YOUR PROGRAMS IN A PROPER AND CONSISTENT CODING STYLE.

5. Write a C++ program with a case structure. The program reads in a character
from the user, then translates it into a different character according to the
following rules:
i. characters X, Y, Z will be translated to characters x, y, z respectively;
ii. the space character ' ' will be translated to underscore '_'
iii. digits 0, 1, 2, .., 9 will all be translated to the question mark '?'
iv. all other characters remain unchanged.

The program then displays the translated character.

NOTE: You can make use of cin.get() to get the next character even if that
character is a white space, see for example,

#include<iostream>
using namespace std;
int main()
{
char ch;
cout << "Enter a char:";
ch=cin.get();
cout << "1st char has code " << unsigned(ch)
<< " and is \"" << ch << "\"\n";
system("pause");
return 0;
}

6. Write a C++ program that reads from keyboard 3 integer numbers, with proper
input prompt, and then display the number that is neither the largest nor the
smallest. You may assume that these 3 numbers are distinct in value, or
consider a number not to be the largest (respectively, smallest) if there is
another number which is larger (respectively, smaller) or equal in value.
7. Write a C++ program with a loop structure that reads in 2 integers, calculates
the sum of all the integers between these 2 integers (not including these 2
integers) if any, and displays the final result. For example, if the 2 integers you
read are -2 and 5, then your program should output 9 (= -1+0+1+2+3+4).
8. Write a function getInterest prototyped by

double getInterest(double base, double rate, int years);

that calculates the accumulated amount of interest on the base amount at the
interest rate rate for years number years. Mathematically, this accumulated
interest can be represented by

Interest = Base * (1 + Rate)Years - Base

Then write a driver program that, for an initial amount of 10000 dollars and

the annual interest rate 3.5%, calculate the total interest earned for 10 years.

IPO Diagram and Pseudocode (2


marks)
9. Develop a Defining Diagram, and construct an algorithm in pseudocode that
reads a series of numbers, until a non-positive number (0, or negative number)
is read, finds the largest among all those that are read, and displays the result.

Note on Submission
o This assignment must be submitted electronically via WebCT before the due
date. No email submissions will be accepted.
o Submitted files may be zipped together as a single zip file (but not as a zipx
file), if a student wishes to do so. However, no other file compression or file
archiving formats will be accepted for the submission.
o All C++ programs must be compilable under Dev-C++ ver 4.9.9.2, or more
precisely, under g++ 3.4.2 (mingw-special).
o The electronic submission should contain the paper work in plain text or in
Microsoft Word format (must be readable on the School's lab computers), and
the C++ source code (the .cpp file(s)) as well as other relevant files if any.
Please do not include the compiled executables as the markers will generate
them for you independently anyway.
o Each submission must be accompanied by a declaration of the ownership of
the submitted work as described in the unit outline and learning guide. Please
note that an examiner or lecturer/tutor has the right not to mark this assignment
if a pertinent declaration is not present in your submission.
o Late submissions will attract a daily incremented late penalty of 10% per day.
o Please note that if your C++ program does not compile, you automatically lose
50% of the marks in the C++ coding part.

You might also like