JMTI - Student Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Navigation
 Index
 Memberlist
 Profile
 FAQ
 Search
Latest topics
» Cara hubungi admin
Exercice TKE EmptyThu Dec 23, 2021 11:20 pm by Optitech

» Sf Car Rental Agency - Perkhidmatan Kereta Sewa Shah Alam
Exercice TKE EmptyWed Sep 09, 2015 2:48 am by sksportcar

» Homestay Di Kota Bharu
Exercice TKE EmptySun Jan 25, 2015 10:52 pm by sksportcar

» Sf Car Rental Agency - Kereta Sewa Shah Alam
Exercice TKE EmptyTue Aug 05, 2014 8:54 am by sksportcar

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

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

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

» Virus shortcut kat pendrive
Exercice TKE EmptyThu Jul 21, 2011 12:27 am by Optitech

» Admin Kembali dengan Menyengat
Exercice TKE EmptyWed Jul 20, 2011 1:59 pm by Optitech


Exercice TKE

Go down

Exercice TKE Empty Exercice TKE

Post  Optitech 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:

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-
Optitech
Optitech

Posts : 519
Join date : 2010-01-01
Age : 32
Location : ProxyFireZ

http://sembangseposen.blogspot.com

Back to top Go down

Back to top


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