Navigation
 Index
 Memberlist
 Profile
 FAQ
 Search
Latest topics
» Perkhidmatan Kereta Sewa Shah Alam
Wed Sep 09, 2015 2:48 am by sksportcar

» Homestay Di Kota Bharu
Sun Jan 25, 2015 10:52 pm by sksportcar

» Kereta Sewa Shah Alam
Tue Aug 05, 2014 8:54 am by sksportcar

» Bahasa Jepun: Ayat Seharian,Hari,Haribulan & Nombor
Mon Sep 23, 2013 8:43 pm by foxfoxer

» Tips nak hapuskan virus secara manual [On updates]
Tue Mar 19, 2013 8:38 am by Optitech

» Teknik defense dari virus and spyware [Auto]
Thu Jul 21, 2011 2:53 am by Optitech

» Virus shortcut kat pendrive
Thu Jul 21, 2011 12:27 am by Optitech

» Admin Kembali dengan Menyengat
Wed Jul 20, 2011 1:59 pm by Optitech

» Xcode Magazine - Penulisan daripada hacker
Wed Jul 20, 2011 12:45 pm by Optitech


Exercice TKE

View previous topic View next topic Go down

Exercice TKE

Post  Optitech on Fri Feb 12, 2010 2:46 am

This exercise is not study thoroughly yet. However im doing my best to complete the assignment with a tight time. I will update the code relevant to the question.

EXERCISE 1: write a program that prints the hundreds digit in a series of integer constants.For example,if constants ONE and TWO are 1456 and 254 respectively,your program should print 4 and 2.You may choose the integers yourself.Your output should include the original number followed by the digit in the hundreds position.Label your output appropriately.

Spoiler:

Sorry, this exercise cannot be done right now.

EXERCISE 2: write a program that prints the number 1349.9431 with three decimal places,with two decimal places and with one decimal place.
Note: I use the setprecision to set the decimal places.

Code:

#include <iostream>
#include <iomanip>
using namespace std;


int main()
{
double no1= 1349.9431;

   cout<<fixed<<showpoint<<setprecision(3);
   cout<<no1<<endl;

   cout<<fixed<<showpoint<<setprecision(2);
   cout<<no1<<endl;

   cout<<fixed<<showpoint<<setprecision(1);
   cout<<no1<<endl;
   return 0;
}

EXERCISE 3: write a program that print each of the following values in two columns :1234,45,7,87,99999.The first column is left justified and the second column is right justified.
Note: i used setw for the justify.

Code:

#include <iostream>
#include <iomanip>
using namespace std;


int main()
{

   cout<<"First Column:\t\t\tSecond Column:"<<endl;
    cout << setw(20) << left<<"1234,45,7,87,99999";


    cout << setw(20) << right<<"1234,45,7,87,99999";
   cout<<endl;

   return 0;

}

EXERCISE 4: write a program that takes string of thirty hash marks (#) and prints six hash marks on five lines with a blank line in between.The variable that originally contains the thirty hash mark should contain the empty string at the end of your program.
Note: This program used looping to make the program shorter.

Code:

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


const string HASH = "#";

int main()
{
int y,x;

for(y=0;y<=5;y++)
{
   cout<<endl;
   for(x=0;x<=6;x++)
   {
      cout<<HASH<<" ";
   }

}
cout<<endl<<endl;
   return 0;

}

Note: I have tried my best to do the assignment. The code maybe not will be satisfied by your lecture. Anyway, it may help you to get some marks. Enjoy. You may contact me if you got any question regarding the exercise.
-Muhammad Haiqal-

_________________
|----------------------------------------------------|




EXCUSE IS THE DUMBEST WAY TO ESCAPE

MAKLUMAN: Worksheet/Assignment Download Section hanya untuk pengguna berdaftar. Sila daftar untuk melakukan 'download'. Lepas dah click link, tekan kat perkataan "Skip Ad" bahagian atas belah kanan sekali. Pastu baru leh download.
Harap Maklum.

Optitech

Posts : 518
Join date : 2010-01-01
Age : 24
Location : ProxyFireZ

http://sembangseposen.blogspot.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum