This is a computer sales program that will display the data table the number of sales to sell computers, which occurred in a computer store.
Here is the source code "How are the sales selling the computer".
#include<iostream>
#include<conio.h>
using namespace std;
class Sales {
public :
Sales();
void print_selling();
void print_sales();
void sum_selling_sales();
void sum_selling_month();
void search_max_selling(int &temp1, int &temp2);
private :
int penjualan[5][5];
char *sales_name[5];
int total_sales[5];
int total_month[5];
};
void Sales::print_selling(){
cout << "Data of selling in the Computer shop (Monthly and Sales) : " << endl;
for (int i=0; i < 5; i++) {
for (int j=0; j < 5; j++) {
cout << penjualan[i][j] << "\t";
}
cout << endl;
}
}
void Sales::print_sales() {
cout << "Name of sales : " << endl;
for (int i=0; i < 5; i++) {
cout << sales_name[i] << "\t";
cout << endl;
}
}
Sales::Sales() {
penjualan[0][0] = 34;
penjualan[0][1] = 15;
penjualan[0][2] = 100;
penjualan[0][3] = 22;
penjualan[0][4] = 55;
penjualan[1][0] = 12;
penjualan[1][1] = 27;
penjualan[1][2] = 10;
penjualan[1][3] = 45;
penjualan[1][4] = 12;
penjualan[2][0] = 6;
penjualan[2][1] = 30;
penjualan[2][2] = 20;
penjualan[2][3] = 15;
penjualan[2][4] = 70;
penjualan[3][0] = 50;
penjualan[3][1] = 20;
penjualan[3][2] = 34;
penjualan[3][3] = 70;
penjualan[3][4] = 24;
penjualan[4][0] = 72;
penjualan[4][1] = 40;
penjualan[4][2] = 62;
penjualan[4][3] = 18;
penjualan[4][4] = 46;
sales_name[0] = "Agus";
sales_name[1] = "Bambang";
sales_name[2] = "Catur";
sales_name[3] = "Dita";
sales_name[4] = "Erna";
}
void Sales::sum_selling_sales() {
cout << "Total selling (Per Sales) : " << endl;
for (int i=0; i < 5; i++) {
total_sales[i] = 0;
for (int j=0; j < 5; j++) {
total_sales[i] += penjualan[i][j];
}
cout << total_sales[i] << endl;
}
}
void Sales::sum_selling_month() {
float rata[5];
cout << "Total selling (Monthly) : " << endl;
for (int j=0; j < 5; j++) {
total_month[j] = 0;
for (int i=0; i < 5; i++) {
total_month[j] += penjualan[i][j];
}
rata[j] = total_month[j]/ 5.0;
cout << total_month[j] << "\t" << rata[j] << endl;
}
}
void Sales::search_max_selling(int &temp1, int &temp2) {
int i, j, max = penjualan[0][0];
for (i = 0; i < 5; i++)
for (j = 0; j < 5; j++)
if (penjualan[i][j] > max)
{ max = penjualan[i][j];
temp1 = i;
temp2 = j;
}
cout << "Top selling is : " << max << " at month : " << temp2 << endl;
cout << "And sales name is : " << sales_name[temp1] << endl;
}
int main(int argc, char *argv[])
{
int a, b;
Sales X;
X.print_selling();
X.print_sales();
X.sum_selling_sales();
X.sum_selling_month();
X.search_max_selling(a,b);
system("PAUSE");
return EXIT_SUCCESS;
}
Selasa, 14 Juni 2011
Menghitung Usia
- Analisis :
Menghitung usia dimana masing masing tanggal dikonversi ke bilangan kemudian dihitung selisihnya.
- Tes Data
Misalnya :
Tanggal sekarang – tanggal lahir = 8 – 8 = 0 hari
Bulan sekarang – bulan lahir = 6 – 4 = 2 bulan
Tahun sekarang – tahun lahir = 2011 – 1992 = 19 tahun
Jadi, umur Aly sekarang adalah 19 tahun 2 bulan 0 hari
- Programnya :
#include <conio.h>
#include <iostream.h>
int main(){
int tgl_skrng,bln_skrng,thn_skrng,tgl_lahir,bln_lahir,thn_lahir,tahun,bulan1,
bulan2,tgl1,tgl2;
cout<<"masukan tanggal sekarang : ";
cin>>tgl_skrng;
cout<<"masukan bulan sekarang : ";
cin>>bln_skrng;
cout<<"masukan tahun sekarang : ";
cin>>thn_skrng;
cout<<endl;
cout<<"masukan tanggal lahir anda: ";
cin>>tgl_lahir;
cout<<"masukan bulan lahir anda : ";
cin>>bln_lahir;
cout<<"masukan tahun lahir anda : ";
cin>>thn_lahir;
cout<<endl;
tahun=thn_skrng-thn_lahir;
bulan1=bln_skrng-bln_lahir;
bulan2=bln_lahir-bln_skrng;
tgl1=tgl_skrng-tgl_lahir;
tgl2=tgl_lahir-tgl_skrng;
{
if((thn_skrng>thn_lahir)&&(tgl_skrng>=tgl_lahir)&&(bln_skrng>=bln_lahir))
{
cout<<"Umur anda: "<<tahun<<" tahun "<<bulan1<< " bulan "<<tgl1<< " hari "<<endl;
}
else if((thn_skrng>thn_lahir)&&(tgl_lahir>=tgl_skrng)&&(bln_lahir>=bln_skrng))
{
cout<<"Umur anda: "<<tahun<< " tahun "<<bulan2<< " bulan " <<tgl2<< " hari "<<endl;
}
else if((thn_skrng>thn_lahir)&&(tgl_skrng>=tgl_lahir)&&(bln_lahir>=bln_skrng))
{
cout<<"Umur anda: "<<tahun<<" tahun "<<bulan2<<" bulan "<<tgl1<<" hari "<<endl;
}
else if((thn_skrng>thn_lahir)&&(tgl_lahir>=tgl_skrng)&&(bln_skrng>=bln_lahir))
{
cout<<"Umur anda: "<<tahun<<" tahun "<<bulan1<<" bulan "<<tgl2<<" hari "<<endl;
}
else
{
cout<<"data yang anda masukan salah"<<endl;
}
}
getch();
}
Selisih Dua Waktu
Analisis :
Mencari selisih dua waktu yang waktu akhir dan awal dikonversikan menjadi detik dan kemudian dihitung selisihnya sehingga menghasilkan selisih waktu.
- Programnya :
#include<iostream.h>
#include<conio.h>
main(){
int j1,m1,d1,j2,m2,d2,d3,d5,w,x,y,z;
cout<<"Masukkan Waktu 1 :"<<endl;
cout<<"Jam = "; cin>>j1;
cout<<"Menit = "; cin>>m1;
cout<<"Detik = "; cin>>d1;
d3=(j1*3600)+(m1*60)+d1;
cout<<"Konversi Waktu 1 ke Detik : "<<d3;
cout<<" "<<endl; cout<<" "<<endl;
cout<<"Masukkan Waktu 2 :"<<endl;
cout<<"Jam = "; cin>>j2;
cout<<"Menit = "; cin>>m2;
cout<<"Detik = "; cin>>d2;
d5=(j2*3600)+(m2*60)+d2;
cout<<"Konversi Waktu 2 ke Detik : "<<d5;
cout<<" "<<endl; cout<<" "<<endl;
d5=d3-d5;
cout<<"Selisih Detik 1 dengan Detik 2 : "<<d5;
cout<<" "<<endl; cout<<" "<<endl;
cout<<"Konversi Selisih ke Waktu :"<<endl;
w=d5/3600;
x=d5%3600;
y=x/60;
z=x%60;
cout<<"Jam = "<<w<<endl;
cout<<"Menit = "<<y<<endl;
cout<<"Detik = "<<z<<endl;
getch();
}
ALGORITMA DAN PROGRAM MENCARI JARAK 2 TITIK
1. Analisis
Mencari jarak dua titik pada sebuah koordinat yang inputannya x1, x2, y1, y2
2. Identifikasi
Input : koordinat A(x1,y1) dan B(x2,y2)
Output : jarak
3. Algoritma
Deklarasi :
x1,x2,y1,y2,a,b : int
jarak : float
Deskripsi :
Baca x1;
Baca x2;
Baca y1;
Baca y2;
jarak=(sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))));
End (Tulis jarak)
4. Program
#include<cstdlib> | ||
#include<iostream.h> | ||
#include <conio.h> | ||
#include<math.h> | ||
using namespace std; | ||
class jarak{ | ||
public: | ||
void dua_titik(); | ||
float jarak_2titik(); | ||
private: | ||
int x1,x2,y1,y2,a,b; | ||
float jarak; | ||
}; | ||
void jarak::dua_titik(){ | ||
cout<<"menghitung jarak dua titik sebuah koordinat"<<endl; | ||
cout<<"masukkan x1 : "; | ||
cin>>x1; | ||
cout<<"masukkan y1 : "; | ||
cin>>y1; | ||
cout<<"masukkan x2 : "; | ||
cin>>x2; | ||
cout<<"masukkan y2 : "; | ||
cin>>y2; | ||
} | ||
float jarak::jarak_2titik(){ | ||
jarak=(sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)))); | ||
cout<<"jadi jaraknya adalah: "<<jarak; | ||
} | ||
int main(int argc, char *argv[]) | ||
{ | ||
jarak X; | ||
X.dua_titik(); | ||
X.jarak_2titik(); | ||
getch(); | ||
return 0; | ||
} |
Minggu, 12 Juni 2011
Record (Rekaman)
Compiled by one or more fields. Each field stores data from certain basic types or from other types of formations that have been defined previously. The name of the recording is determined by the programmer.
Define class to record time
Define class to record time
#include <iomanip>
#include <iostream>
using std::cout;
using std::endl;
using std::setfill;
using std::setw;
class Time
{
public:
Time();
void setTime( int, int, int );
void printUniversal();
void printStandard();
private:
int hour;
int minute;
int second;
};
Time::Time()
{
hour = minute = second = 0;
}
void Time::setTime( int h, int m, int s )
{
hour = h ;
minute = m;
second = s ;
}
void Time::printUniversal()
{
cout << setfill( '0' ) << setw( 2 ) << hour << ":" << setw( 2 ) << minute << ":" << setw( 2 ) << second;
}
void Time::printStandard()
{
cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour "
<< setfill( '0' ) << setw( 2 ) << minute << ":" << setw( 2 )
<< second << ( hour < 12 ? " AM" : " PM" );
}
int main()
{
Time t;
t.printUniversal();
t.printStandard();
t.setTime( 1, 2, 6 );
t.printUniversal();
t.printStandard();
t.setTime( 99, 99, 99 );
t.printUniversal();
t.printStandard();
return 0;
}
Listen
Read phonetically
Langganan:
Postingan (Atom)