2.โปรแกรมแสดงตารางสูตรคูณ[input basic]

พูดคุย, ปรึกษาการพัฒนาโปรแกรม
และ case study

Moderator: bigaun

2.โปรแกรมแสดงตารางสูตรคูณ[input basic]

Postby bigaun » Sat Nov 18, 2006 8:23 pm

ให้เขียนโปรแกรม MulTable ซึ่งเป็นโปรแกรมแสดงตารางสูตรคูณ ซึ่งมาจากการคํานวณของ
โปรแกรม โดยให้ผู้เขียนทําการรับค่า2 ค่าคือ

􀂃 ตั้งแต้สูตรคูณแม่ X
􀂃 ถึงสูตรคูณแม่ Y

โดย Output ที่ได้แสดงผลดังนี้

Multiplication Table
2 Times Table
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
2 x 11 = 22
2 x 12 = 24
-----------------
3 Times Table
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
3 x 11 = 33
3 x 12 = 36
-----------------
4 Times Table
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40
4 x 11 = 44
4 x 12 = 48
-----------------
5 Times Table
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
5 x 11 = 55
5 x 12 = 60
-----------------
Aun # 17
User avatar
bigaun
Moderators
 
Posts: 2022
Joined: Wed Jun 22, 2005 3:13 pm
Location: Live in webboard

Postby bigaun » Thu Nov 23, 2006 2:32 pm

/* MulTable.h
*
* Author Mr.Prapas Rangnim
*
*/

class MulTable
{
public:
MulTable(){}
~MulTable(){}
void showMulTable();

void setX(int init);
int getX();

void setY(int finish);
int getY();

private:
int x;
int y;

};
Aun # 17
User avatar
bigaun
Moderators
 
Posts: 2022
Joined: Wed Jun 22, 2005 3:13 pm
Location: Live in webboard

Postby bigaun » Thu Nov 23, 2006 2:36 pm

/* MulTable.cpp
*
* Author Mr.Prapas Rangnim
*
*/

#include "MulTable.h"

#include <cstdlib>
#include <iostream>

using namespace std;

void MulTable::showMulTable()
{
cout<<"Multiplication Table\n";
for(int i=getX(); i<=getY(); i++)
{
cout<<i<<" Times Table\n";
for( int j=1; j<=12; j++)
{
cout<<i<<" x "<<j<<"= "<<i*j<<endl;
}//end for j
cout<<"-------------\n";
}// end for i

}//end showMulTable method


void MulTable::setX(int init)
{
x = init;
}// end setX method

int MulTable::getX()
{
return x;
}//end getX method

void MulTable::setY(int finish)
{
y = finish;
}// end setY method

int MulTable::getY()
{
return y;
}//end getY method
Aun # 17
User avatar
bigaun
Moderators
 
Posts: 2022
Joined: Wed Jun 22, 2005 3:13 pm
Location: Live in webboard

Postby bigaun » Thu Nov 23, 2006 2:40 pm

/* This is program that show Multiple Table.
*
* main.cpp
*
* Author Mr.Prapas Rangnim
*
*/

#include <cstdlib>
#include <iostream>
#include "MulTable.h"

using namespace std;

int main(int argc, char *argv[])
{
MulTable mul;
int init=0,finish=0;
cout<<"Enter initial value for multiple table: ";
cin>>init;
cout<<"Enter finish value for multiple table: ";
cin>>finish;

mul.setX(init);
mul.setY(finish);

mul.showMulTable();
system("PAUSE");
return EXIT_SUCCESS;
}
Aun # 17
User avatar
bigaun
Moderators
 
Posts: 2022
Joined: Wed Jun 22, 2005 3:13 pm
Location: Live in webboard

Postby nat3 » Thu Nov 23, 2006 9:44 pm

ชะอุ้ย นึกว่าโค้ดไร เดี๊ยวนึกก่อนเอาไรมาใส่ดี
User avatar
nat3
Moderators
 
Posts: 1229
Joined: Mon Jun 13, 2005 12:52 pm

Postby Poron » Thu Nov 23, 2006 10:11 pm

คุ้นๆแหะ เหมือนแอสซายเรย เหอๆ
บิ๊กกี้คุง #21
see me @ BiggyClub

Image
User avatar
Poron
Member
 
Posts: 609
Joined: Sun May 28, 2006 2:17 am
Location: http://biggyclub.co.cc

Postby bigaun » Fri Nov 24, 2006 5:19 am

เอามาจากการบ้าน java เลยแปลงเป็น c++อ่ะ
Aun # 17
User avatar
bigaun
Moderators
 
Posts: 2022
Joined: Wed Jun 22, 2005 3:13 pm
Location: Live in webboard


Return to Programming / Web-Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron