0% found this document useful (0 votes)
17 views5 pages

Program Array dan Gaji Karyawan

The document contains code for a C# program that manages employee payroll data. It initializes arrays to store employee names, salaries, allowances, and total pay. It then prints a payroll report to the console showing the employee name, allowances, and total pay for each employee. It also calculates and prints the total payroll amount.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Program Array dan Gaji Karyawan

The document contains code for a C# program that manages employee payroll data. It initializes arrays to store employee names, salaries, allowances, and total pay. It then prints a payroll report to the console showing the employee name, allowances, and total pay for each employee. It also calculates and prints the total payroll amount.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

using System;
using [Link];
using [Link];
using [Link];

namespace ARRAY
{
class Program
{
static void Main(string[] args)
{

int[] kode = new int[100];

int[] lama = new int[100];

double[] harga = new double[100];

double[] total = new double[100];

string[] jenis = new string[20];

int i, n = 0;

[Link]("Masukan Jumlah Input: ");

n = [Link]([Link]());

for (i = 1; i <= n; i++)

[Link](" Masukan Kamar ke-" +i);

[Link]("\t Masukan Kode Kamar : ");

kode[i] = [Link] ([Link]());

[Link]("\t Masukan Lama Inap : ");

lama[i] = [Link] ([Link]());

if (kode[i] == 1)

{
harga[i] = 100000;

jenis[i] = " VIP ";

else if (kode[i] == 2)

harga[i] = 200000;

jenis[i] = "Double";

else

jenis[i] = " kode kamar salah !";

total[i] = lama[i] * harga[i];

[Link]();

[Link]("|=========================|");

[Link]("\nFakuktas Teknologi Komunikasi dan Informatika ");


[Link]("\nProgram Studi Teknik Informatika ");
[Link]("\nUNIVERSITAS NASIONAL ");

[Link]("|=========================|");

[Link]("No | Kode Kamar | Jenis Kamar | Harga | Lama Inap | Total


Harga |");

[Link]("---------------------------");

for (i = 1; i <= n; i++)

[Link](i + " \t " + kode[i] + " \t " + jenis[i] + " \t " +


harga[i] +" " + lama[i] + "\t " + total[i] + " ");

[Link]("===========================");

[Link](" TERIMA KASIH ");

[Link]();
}

}
2.

using System;
using [Link];
using [Link];
using [Link];

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{

[Link]("===================================================================");
[Link]("\nFakultas Teknologi Komunikasi dan Informatika");
[Link]("\nprogram studi system informasi");
[Link]("\nUNIVERSITAS NASIONAL");

[Link]("===================================================================");

[Link]("-------------------------------------------------------------------");
[Link]();
[Link](" DATAKARYAWAN ");
[Link]("[Link] TECHNOLOGY");
[Link]();
[Link]("No | nama karyawan |tunjangan jabatan | tunjangan
pendidikan | Honor lembur | Gaji Bersih |");
for (int i = 0; i <= 2; i = +1)
{
string[] nama = new string[3] { "sopiyan", "udin ", "bagus " };
double[] tunjangan_jabatan = new double[3] { 8000000, 6000000, 7000000 };
double[] tunjangan_pendidikan = new double[3] { 2000000, 1000000, 5000000
};
double[] gaji = new double[100];
double[] gajibersih = new double[100];
double total;
for (int n = 0; n <= 2; n++)
{

gajibersih[i + n] = tunjangan_pendidikan[i + n] + tunjangan_jabatan[i


+ n];

[Link]("----------------------------------------------------------------------
--------------------------");
[Link](n + 1 + " " + nama[i + n] + "\t\t " +
tunjangan_jabatan[i + n] + "\t\t " + tunjangan_pendidikan[i + n] + " \t 0 \t" +
gajibersih[i + n]);
}

[Link]("----------------------------------------------------------------------
--------------------------");
total = gajibersih[0] + gajibersih[1] + gajibersih[2];
[Link]("total gaji yang dikeluarkan :" + total);
[Link]();
}
}
}
}

Common questions

Powered by AI

In Source 1, the program manages room data using arrays for different attributes such as room code, stay duration, price, and total cost, relying heavily on user input for the number of entries and specifics. This includes calculations based on conditions. In contrast, Source 2 handles employee data using predefined arrays for names, job allowances, and educational allowances. The program calculates total salary directly without needing user input beyond triggering the print operations. There is a mixed use of loop iterations and static indexing .

Source 1 uses user feedback prompts directly to gather and confirm input for each room, while Source 2 primarily outputs predefined data without requiring further user interaction. Standardizing user feedback could include consistent prompts for inputs, clear error messages, and uniform formatting for displaying results, enhancing usability by ensuring users know what information the system is processing and its current state. Standardizing feedback across Sources could include real-time validation and inclusion of summary feedback post-process .

Potential errors could include IndexOutOfRangeExceptions if the arrays are accessed with indices that are not initialized, especially if user input exceeds predefined array sizes. In Source 1, starting array indices at '1' instead of '0' could lead to unintentional overwriting or skipped entries. This can be mitigated by initializing arrays dynamically based on the exact number of entries required or by adjusting loop indices to match array starting points. Source 2's approach could fail if additional employees require more indexes than those hardcoded, which can be solved by dynamic array allocation or using collections like List for flexibility .

Modularity allows code to be broken into manageable, reusable sections, improving readability, maintenance, and debugging. Neither Source 1 nor Source 2 actively employs modular methods such as functions or classes, which can make understanding and extending each program tougher. By converting repetitive operations such as calculations or print statements into functions, changes could be centralized, reducing error probability and duplicative code management efforts. This would allow developers to address faults more efficiently and facilitate feature scalability, without the need to alter base operation logic frequently .

The calculation of total room cost in Source 1 is dynamic; it depends on user input for both the number of entries and the stay duration for each room, computing individual totals by multiplying stay duration by the price determined by code. For total salaries in Source 2, it is a simple summation of static values: job and education allowances are summed for each employee, presuming no variation in basic input. The room cost uses loops with conditionals for error checking, while total salaries are hardcoded and summed in pre-determined loops .

Both programs lack data validation mechanisms. Implementing validation could include checking for valid integer entries or room codes before storing inputs, ensuring accurate pricing and types in Source 1. Similarly, for Source 2, verifying employee entries and allowances ensure consistent data entry. Using exception handling around parse operations in Source 1 and validating against a known list before operations in Source 2 could enhance data accuracy. Ensuring inputs conform to expected ranges and formats would prevent potential runtime errors and inaccuracies .

Optimization could include restructuring loops and removing duplicated calculations. For Source 1, ensuring loop operations only iterate over necessary elements and avoiding recalculating static values inside loops would conserve resources. For Source 2, considering collections like Lists could streamline executions when handling larger or variable employee data sets, removing the need to iterate over unset values. Unnecessary clearing of the console should be reduced or replaced with efficient output management. Code refactoring to minimize redundant operations would also enhance speed without changing outputs .

Documentation plays a critical role in understanding code logic, purpose, and inherent assumptions. Neither Source 1 nor Source 2 has inline comments explaining sections of code or decision logic, which can hinder comprehension and proper debugging or enhancement. Comprehensive documentation would involve commenting on each major section, detailing purpose, expected inputs/outputs, error handling, and assumptions. This aids new developers in understanding existing architecture quickly, ensuring continuity amidst staff changes, and facilitating smoother extensions and debugging .

The program in Source 1 determines the pricing and type of room using conditional statements (if-else). When a room code is inputted, it checks if the code is '1', setting the price to 100,000 and type to 'VIP'. If the code is '2', the price is set to 200,000 and the type to 'Double'. If neither condition is met, it outputs an error message 'kode kamar salah !' for the room type .

Static array sizing poses significant scalability challenges; as input needs grow beyond the initial fixed size, these arrays cannot automatically expand, leading to data truncation or overwrites. This requires accurate pre-assessment of size needs, which is often impractical in dynamically scaling systems. Implementing dynamic data structures, like Lists in C#, could seamlessly accommodate more data and handle variable input sizes. By relying on static sizes, both examples risk data loss and overflow errors without additional management backup, limiting flexible data management .

You might also like