pert 7 soal 3

Tugas 7-3

 

Kerjakan latihan nomor 4 . hal 124, Bab. Communication between modules

dari buku Simple Program Design, edisi ke dua.

File data.txt isinya misalnya…

P01;anto;5000

P02;santo;1000

P03;toni;2000

 

 

 

#include <iostream>

#include <fstream.h>

#include <stdlib.h>

int main()

{

char str[40],*p;

char kode[10][4],nama[10][30];

double nilai[10],comisi[10];

int i;

i=0;

fstream in(“data.txt”,ios::in);

while(!in.eof())

{

in.getline(str,40);

p=strtok(str,”;”);

if(p!=NULL)

{

strcpy(kode[i],p);

p=strtok(NULL,”;”);

strcpy(nama[i],p);

p=strtok(NULL,”");

nilai[i]=atoi(p);

i++;

}

}

for(int j=0;j<i;j++)

{

if(nilai[j]>=0&&nilai[j]<=199){

comisi[j]=nilai[j]*5;

}

else if(nilai[j]>=200&&nilai[j]<=999){

comisi[j]=(200*5)+((nilai[j]-200)*8);

}

else if(nilai[j]>=1000&&nilai[j]<=1999){

comisi[j]=(200*5)+((1000-200)*8)+((nilai[j]-1000)*10);

}

else if(nilai[j]>=2000){

comisi[j]=(200*5)+((1000-200)*8)+((2000-1000)*10)+((nilai[j]-2000)*12);

}

cout.setf(ios::fixed);

cout.precision(0);

cout<<kode[j]<<” “<<nama[j]<<” “<<nilai[j]<<”comisi :”<<comisi[j]<<endl;

}

cin.get();

return 0;

}

Explore posts in the same categories: MPP

Tinggalkan Balasan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Ubah )

Twitter picture

You are commenting using your Twitter account. Log Out / Ubah )

Facebook photo

You are commenting using your Facebook account. Log Out / Ubah )

Connecting to %s


Ikuti

Get every new post delivered to your Inbox.