Latest topics
Exercice TKE
Page 1 of 1
Exercice TKE
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.
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.
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.
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.
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-
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-
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Thu Dec 23, 2021 11:20 pm by Optitech
» Sf Car Rental Agency - 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
» Sf Car Rental Agency - 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