The programmer's corner.

Please post computer issues here. We will try to help you. Also for showing off your PC.
Peter
The Cluckin' Godfather
Posts: 7056
Joined: Tue Aug 16, 2011 10:11 am
KCNR Username: Peter
Location: Hell
Status: Offline

Sat Jun 24, 2017 12:34 am

Just a small project to demonstrate web applications.
It's on GitHub, it features Flask (Python), Materialize (CSS framework), RiotJS (JavaScript framework) and Pug (Easier way for HTML).
https://github.com/selten/flask-materialize-riot-pug
Image

Want your own statistics counter? Look right here: viewtopic.php?f=25&t=1216
(Feature) introduction topic: viewtopic.php?f=25&t=28493
[Rw]Joel
SWAT Commander
Posts: 1624
Joined: Mon Dec 12, 2011 7:19 am
KCNR Username: [Rw]Joel
Status: Offline

Sun Jun 25, 2017 6:48 pm

So after a week into the programming class, I realised the programming I learnt before was not anything like this.

Having no real experience in programming, I found it actually pretty damn easy as compared to my classmates (some are struggling badly). I think it was sort of made easier through AutoHotKey for KCNR to sort through syntax error.


My class is currently in looping, after branching and fundamentals. I wanted to do something complicated, seeked my lecturer and he said maybe a timezone converter that takes the time from your system to convert the time.

And so thats what I did. I'm sure this is really basic to others, but it was satisfying watching this code work.

Note: Time will probably be wrong if you use first choice in places that arent GMT+8

Code: Select all

#include <stdio.h>
#include <time.h>
#include <ctype.h>

int choice,ttz,otz,tzdif,oMin,oHours,nHours;
char ttzdst,otzdst,loop;


void GMT(void);
void menu(void);
void choice_one(void);
void choice_two(void);
void end(void);


void main(void)
{



    time_t rawtime;
    struct tm*timeinfo;
    
    loop = 'Y';

    while (loop == 'Y')
    {

        menu();

        switch (choice)
        {
            case 1 : GMT();
                    printf("Please input the target time zone: ");
                    scanf("%i",&ttz);
                    choice_one();
                    
                    break;

            case 2 : GMT();                
                    choice_two();
                   
                    break;

            default : printf("Invalid choice! Bye-bye!");
                    break;
        }

    printf("Do you want to try again?(Y/N) ");
    scanf(" %c",&loop);
    loop = toupper(loop);

    }

    end();

}


void menu(void)
{

        printf("\n\n=================================================\n");
        printf("MENU\n");
        printf("=================================================\n");
        printf("1. Convert Singapore local time to another timezone\n");
        printf("2. Convert a specific timezone to another timezone\n");
        printf("Pick a choice: ");
        scanf("%i",&choice);
}

void GMT(void)

{
        printf("\n\n================================================================================");
        printf("\nThis is timezones listed with their principal cities:\n");
        printf("UTC - 12   Baker Island, Howland Island\n");
        printf("UTC - 11   Midway, Palmyra\n");
        printf("UTC - 10   Honolulu, Papeete\n");
        printf("UTC - 09   Anchorage\n");
        printf("UTC - 08   Los Angeles, Vancouver, Tijuana\n");
        printf("UTC - 07   Phoenix, Calgary, Ciudad Jua\n");
        printf("UTC - 06   Chicago, Guatemala City, Mexico City, San Jose, San Salvador\n");
        printf("UTC - 05   New York, Lima, Toronto, Bogota, Havana, Kingston\n");
        printf("UTC - 04   Caracas, Santiago, La Paz, Manaus, Halifax, Santa Domingo\n");
        printf("UTC - 03   Buenos Aires, Montevideo, Sao Paulo\n");
        printf("UTC - 02   Fernando de Noronha, South Georgia\n");
        printf("UTC - 01   Cape Verde, Greenland, Azores Island\n");
        printf("UTC   00   Accra, Casablanca, Dakar, Dublin, Lisbon, London\n");
        printf("UTC + 01   Berlin, Lagos, Madrid, Paris, Rome, Tunis, Vienna, Warsaw\n");
        printf("UTC + 02   Athens, Bucharest, Cairo, Helsinki, Jerusalam, Johannesburg, Kiev\n");
        printf("UTC + 03   Istanbul, Moscow, Nairobi, Baghdad, Doha, Khartoum, Misk, Riyadh\n");
        printf("UTC + 04   Baku, Dubai, Samara, Muscat\n");
        printf("UTC + 05   Karachi, Tashkent, Yekaterinburg\n");
        printf("UTC + 06   Almaty, Dhaka, Omsk\n");
        printf("UTC + 07   Jakarta, Bangkok, Novosibirsk, Hanoi\n");
        printf("UTC + 08   Beijing, Taipei, Singapore, Kuala Lumpur, Perth, Manila, Denpasar,\n");
        printf("UTC + 09   Seoul, Tokyo, Ambon, Yakutsk\n");
        printf("UTC + 10   Port Moresby, Sydney, Vladivostok\n");
        printf("UTC + 11   Noumea\n");
        printf("UTC + 12   Auckland, Suva\n");
        printf("UTC + 13   Apia, Nuku'alofa\n");
        printf("UTC + 14   Line Islands\n");
        printf("================================================================================\n\n");
        printf("A list of timezones and their principal cities has been provided above for your reference\n");


}

void end(void)

    {
    printf("\n\nThank you for using Joel's Timezone Converter.\n");
    printf("Bye-Bye!");
    }



void choice_one(void)
{
    
        time_t rawtime;
        struct tm*old;
        // learnt from http://stackoverflow.com/questions/5141960/get-the-current-time-in-c
        time(&rawtime);
        old = localtime(&rawtime);



        printf("Current Singapore Time:%s\n",asctime(old));

        printf("Current Time in GMT %i:",ttz);



        size_t hours   = ttz - 8;
        time_t newTime = rawtime + (60 * 60 * hours); // derived from http://stackoverflow.com/questions/25136657/how-do-i-use-tm-structure-to-add-minutes-to-current-time
        struct tm*new;
        new = localtime (&newTime);

        printf("%s\n",asctime(new));

   

}


 
void choice_two(void)

{
    printf("Please input the original timezone: UTC ");
    scanf("%i", &otz);




    printf("Is original timezone in daylight saving time now? (Y/N)");
    scanf(" %c", &otzdst);
    printf("Please input the target timezone: UTC ");
    scanf("%i", &ttz);
    printf("Is target timezone in daylight saving time now? (Y/N)");
    scanf(" %c", &ttzdst);

    if (otzdst == 'Y')
    { otz = otz + 1; }

    if (ttzdst == 'Y')
    { ttz = ttz + 1; }

    printf("Please input the time (24-hour) in original timezone in HH MM 24-hour format (eg. 18 05 for 6:05pm)");
    scanf("%i %i", &oHours,&oMin);

    tzdif = ttz-otz;

    nHours = oHours + tzdif;

    if (nHours < 24 && nHours > 0) 
        {
        printf("While the local time of GMT %i is %02i:%02i,",otz,oHours,oMin);
        printf("the local time of GMT %i is %02i:%02i.",ttz,nHours,oMin); 
        }

    else if (nHours > 24)
        {
        nHours = nHours - 24;
        printf("While the local time of GMT %i is %02i:%02i,\n",otz,oHours,oMin);
        printf("the local time of GMT %i is %02i:%02i in the next day.",ttz,nHours,oMin);
        }
    else if (nHours < 0)
        {
        nHours = nHours + 24;
        printf("While the local time of GMT %i is %02i:%02i,\n",otz,oHours,oMin);
        printf("the local time of GMT %i is %02i:%02i in the previous day.", ttz, nHours,oMin);
        }
   
}


I'm sure there is a lot for me to improve on, and the coding isnt really that nice imo, but if there is anything that I'm doing wrong please do tell me.

First subject/module in forever that I had such fun
Image
Pilot of the Year 2016

Media Content Creator of the Year 2016

Special thanks to Ragnarok who created this signature
Spoiler!
Image
nrg700
Big Chick
Posts: 70
Joined: Fri Mar 29, 2013 9:05 am
KCNR Username: nrg700
Location: I won't tell ya ;)
Contact:
Status: Offline

Sun Jul 23, 2017 7:07 pm

Hi Everybody, i'd like to share this line of codes and Story? (Also to Exercise my brain OwO)

This was my Final Project for my Programming Class. The Story behind it is quitely funny. it supposed to be a group work but i did it mostly alone because most of my group members couldn't coding really that well. Our Lecturers told us that our project should contain Looping Algorithm,Pointer,and QUEUE Algorithm also Struct.

I did the task as good as i can and i have contained every single algorithm which she has already mentioned but why did she give me 90 (Maybe because of bad Presentation :( ). //meh my english :( (most of the code explanations are in Indonesian ,Variabels are mostly in Indonesian as well)

C++

Code: Select all

#include <iostream>
#include <cstdlib>
#include <cstring>
//#include <string> //to_string , string.cstr()
//#include <algorithm> // reverse
#define maxantri 10
#define maxsize 100
using namespace std;
//Structure Data Mahasiswa
struct Mahasiswa
{
	string nama;
	string tgllahir;
	string sklasal;
	string kode;
	int jrspilih;
	int biaya;
};

//class untuk Queue dan Proses lain
class Queue
{
	private:
	int depan;
	int belakang;
	int dtbs; // Jumlah Database
	public :
	Mahasiswa antri[maxantri]; //array of queuers' data
	Mahasiswa selesai[maxsize]; //array of Datas (Database)
	Queue() : depan(0) , belakang(0) , dtbs(0) {}
	void ShowAllinDatabase();
	void ShowByName(int sementara,string name);
	void ShowAntrian();
	void Enqueue(Mahasiswa que);
	void Dequeue(int sementara);
	bool isFull();
	bool isEmpty();
	bool isDatabaseEmpty();
};

class Process
{
	public:
	int Biaya(int jurusan);
	string SetCode(int jurusan, int nodaft);
	string jurusan(int jrs);
};
/*-------------------------------------------------------------------------
------------------ Definisi Fungsi-fungsi kelas Queue--------------------
---------------------------------------------------------------------------*/
bool Queue::isFull(){
	if(belakang = maxantri)
	{
		return true;
	}
	else
	{
		return false;
	}
}
bool Queue::isEmpty()
{
	if(belakang = 0)
	{ 
		return true;
	}
	else
	{
		return false;
	}
}
bool Queue::isDatabaseEmpty(){dtbs = 0;} //Cek Apabila Database Kosong
void Queue::Enqueue(Mahasiswa que)//Fungsi Untuk Queue
{
	if(!isFull())
	{
		antri[belakang] = que; //untuk yg pertama masih 0
		belakang++; //kemudian tambah 1		
	}
	else
	{			
		cout << "Antrian Penuh" << endl;
	}
	
}
void Queue::Dequeue(int sementara) //Memproses Pengantri Terdepan agar datanya bisa dimasukkan ke database
{
	if(isEmpty())
	{
		cout << "Antrian Tidak Ada" << endl;
	}
	else
	{
		selesai[sementara] = antri[depan];
		for(int i = 0; i < belakang; i++)
		{
			antri[i] = antri[i+1];
		}		
		dtbs++;		
		belakang --;
	}
}


void Queue::ShowByName(int sementara,string name) //Mencari Nama Pada Database 
{
	int kiri,kanan,tengah;
	bool ketemu = false;
	kiri = 0;
	kanan = sementara - 1;	
	if(isDatabaseEmpty())
	{
		cout << "Database Kosong" << endl;
	}
	else
	{
		while(kiri<=kanan) // Menggunakan Teknik Searching Binary Search
		{
			tengah = (kiri+kanan)/2;
			if(selesai[tengah].nama == name)
			{
				ketemu = true;
				break;
			}
			else if(selesai[kanan].nama != name)
			{
				kanan = tengah - 1;
			}
			else if(selesai[kiri].nama != name)
			{
				kiri = tengah + 1;
			}
		}
		if(ketemu == true)
		{
			cout << "-------------------------------" << endl;
			cout << "No.Pendaftaran \t: " << selesai[tengah].kode << endl;
			cout << "Nama \t: " << selesai[tengah].nama << endl;
			cout << "Tempat/TL \t: " << selesai[tengah].tgllahir << endl;
			cout << "Sekolah Asal \t: " << selesai[tengah].sklasal << endl;
			cout << "Jurusan yang dipilih \t: " << selesai[tengah].jrspilih << endl;
			cout << "Biaya \t: " << "Rp." << selesai[tengah].biaya << ",00" << endl;
		}
		else
		{
			cout << "Nama Tak ditemukan" << endl;
		}
	
	}
}

void Queue::ShowAllinDatabase() //Menampilkan Seluruh nama pada Database
{
	if(isDatabaseEmpty())
	{
		cout << "Database Kosong" << endl;
	}
	else
	{	
		for(int i = 0; i < dtbs; i++)
		{
			cout << i + 1 << "." << selesai[i].nama << " "<< selesai[i].kode << endl;
		}
	}
}

void Queue::ShowAntrian()
{
	if(isEmpty())
	{
		cout << "Antrian Kosong" << endl;
	}
	else
	{	
		for(int i = depan; i < belakang; i++)
		{
			cout<< i << "." << antri[i].nama <<endl;
		}
	}
}
/*-------------------------------------------------------------------------
------------------ Definisi Fungsi-fungsi kelas Process--------------------
---------------------------------------------------------------------------*/
string Process::jurusan(int jrs)
{
	switch(jrs)
	{
		case 1:
		return "S1K_001";
		case 2:
		return "S1K_002";
		case 3:
		return "S1K_003";
		case 4:
		return "S1K_004";
	}
}
int Process::Biaya(int jurusan)
{
	if(jurusan == 1){return 23510000;}
	else if(jurusan == 2){return 21780000;}
	else if(jurusan == 3){return 25930000;}
	else if(jurusan == 4){return 21300000;}
}

string Process::SetCode(int jurusan1, int nodaft)
{
	return jurusan(jurusan1) + to_string(nodaft);
}
/*------------------------------------------------------------
--------------------- Fungsi Main ----------------------------
-------------------------------------------------------------*/
int main(void)
{	
	bool selesai = false; //Mengecek apabila perulangan ingin diselesaikan
	int input; //Untuk menyimpan Inputan
	int input2; //menyimpan Inputan kedua
	char pilihan;	//menyimpan inputan pilihan untuk menghentikan perulangan
	int nomorantri = 0;
	string names;	
	Process prs;
	Queue que;
	Mahasiswa tmp;
	do
	{
		cout <<"Program Antrian Pendaftaran Mahasiswa Baru Univ. Amikom" << endl;
		cout <<"1.)Tambahkan Orang ke Antrian" << endl;
		cout <<"2.)Proses Antrian" << endl;
		cout <<"3.)Tampilkan Semua Nama" << endl;
		cout <<"4.)Mencari Nama"<< endl;
		cout <<"5.)Tampilkan Antrian"<<endl;
		cout <<"6.)Exit Program" <<endl;
		cout <<"Inputan Program : ";
		cin >> input;
		switch(input)
		{
			case 1:
				nomorantri++;
				cout << "Inputkan Nama \t: ";
				cin >> tmp.nama;
				cout << "Inputkan Tempat Tanggal Lahir \t:";
				cin >> tmp.tgllahir;
				cout << "Inputkan Sekolah Asal \t:";
				cin >> tmp.sklasal;
				/*cout << "Pilih Jurusan :" << endl;
				cout << "1.) S1-Teknik Informatika" << endl;
				cout << "2.) S1-Sistem Informasi" << endl;
				cout << "3.) S1-Teknologi Informasi" << endl;
				cout << "4.) S1-Teknik Komputer" << endl;
				cout << "Masukkan Jurusan : " << endl;				
				cin >> input2;*/
				tmp.biaya = prs.Biaya(tmp.jrspilih);
				tmp.kode = prs.SetCode(tmp.jrspilih,nomorantri);
				que.Enqueue(tmp);
				break;
			case 2:
				que.Dequeue(nomorantri); //
				break;
			case 3:
				que.ShowAllinDatabase();
				break;
			case 4:
				cout << "Inputkan Nama:" << endl;
				cin >> names;				
				que.ShowByName(nomorantri,names);
				break;
			case 5:
				que.ShowAntrian();
				break;
			case 6:
				cout << "Keluar dari Program [Y/N]?" << endl;
				cin >> pilihan;
				if(pilihan == 'Y' || pilihan == 'y')
				{
					selesai = true;
				}
				else if(pilihan == 'N' || pilihan == 'n')
				{
					selesai = false;
				}							
				break;
		}
	}while(selesai != true);
	return 0;
	
}

//  2 3 4 5 6 7 8
// 1 -> Database[\code]
Forum's Ghost
Post Reply