01/10/2018, 00:28

Nhập môn Java cần anh em giúp đỡ

Mình code bài tập này từ C giờ mình muốn chuyển nó sang java thi làm như thế nào vậy mấy bạn?

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
/* HIDE FUNCTION FOR DEVELOPER: 205. Print current i */
char del1[8],del2[50];
struct student{
    char sid[8];
    char sname[50];
    char sdob[50];
    char semail[50];
    char sphone[50];
    char saddress[50];
} student_list [1000];
void add(int *i){
    g12:
    printf("Input student ID: "); fflush(stdin); gets(student_list[*i].sid);
    if (strlen(student_list[*i].sid)==7)
{
	int result1, result2, result3;
	result1 = strncmp(student_list[*i].sid,"GC", 2);
	result2 = strncmp(student_list[*i].sid,"GT", 2);
	int j=2;
	do {
   		 result3=isdigit(student_list[*i].sid[j]);
    		 j++;
   		 if (result3==0)
     		   break;
	   }
while (j< strlen(student_list[*i].sid)-1);
if ((result1 ==0) || (result2 ==0))
    {if (result3 !=0)
	goto g11;
    else
        {printf("The Student ID is not valid.(GTxxxxx or GCxxxxx)Press *Enter* to input again! "); getchar();
	goto g12;}}
    else
      	{printf("The Student ID is not valid.(GTxxxxx or GCxxxxx)Press *Enter* to input again! "); getchar();
	goto g12;}
}
	 else
      	{printf("The Student ID is not valid.(GTxxxxx or GCxxxxx)Press *Enter* to input again! (GTxxxxx or GCxxxxx)"); getchar();
	goto g12;}
g11:
    printf("Input student name: "); fflush(stdin); gets(student_list[*i].sname);
    printf("Input student date of birth: ");fflush(stdin); gets(student_list[*i].sdob);
    printf("Input student email: ");fflush(stdin); gets(student_list[*i].semail);
    printf("Input student sphone: ");fflush(stdin); gets(student_list[*i].sphone);
    printf("Input student address: ");fflush(stdin); gets(student_list[*i].saddress);
    *i=*i+1;
}
search (int i){
char *test;
char s[50],x1[50],x2[50];
int u=0;
printf("Please enter student's name or a part of it: "); fflush(stdin);gets(s);
int a;
for (a=0;a<i;a++)
{
    strcpy(x1,student_list[a].sname);
    strcpy(x2,s);
    test = strstr(strlwr(x1),strlwr(x2));
    if (test){
        printf("%s | %s | %s | %s | %s | %s |
",student_list[a].sid,student_list[a].sname,student_list[a].sdob,student_list[a].semail,student_list[a].sphone,student_list[a].saddress);
        u++;}
}
if (u==0) printf("No data found!");
getchar();
}
void update(int i){
int test;
char ud[8],x1[8],x2[8];
int u=0;
int c,up;
printf("Enter student ID: ");fflush(stdin); gets(ud);
int a;
for (a=0;a<i;a++)
{
    strcpy(x1,student_list[a].sid);
    strcpy(x2,ud);
    test = strcmp(strlwr(x1),strlwr(x2));
//a chinh la gia tri THUC cua position trong maang
if (test==0)
{
printf("Current student ID: %s
",student_list[a].sid);
printf("Enter 1 to update & 0 to keep: "); scanf("%d",&up);
if (up==1)
	 {printf("Enter a new ID: "); fflush(stdin);gets(student_list[a].sid);}
printf(" Current student name: %s
",student_list[a].sname);
printf("Enter 1 to update & 0 to keep: "); scanf("%d",&up);
if (up==1)
	 {printf("Enter a new name: "); fflush(stdin);gets(student_list[a].sname);}
printf(" Current student date of birth: %s
",student_list[a].sdob);
printf("Enter 1 to update & 0 to keep: "); scanf("%d",&up);
if (up==1)
	 {printf("Enter a new date of birth: "); fflush(stdin);gets(student_list[a].sdob);}
printf(" Current student email: %s
",student_list[a].semail);
printf("Enter 1 to update & 0 to keep: "); scanf("%d",&up);
if (up==1)
	 {printf("Enter a new email: "); fflush(stdin);gets(student_list[a].semail);}
printf(" Current student phone: %s
",student_list[a].sphone);
printf("Enter 1 to update & 0 to keep: "); scanf("%d",&up);
if (up==1)
	 {printf("Enter a new phone: "); fflush(stdin);gets(student_list[a].sphone);}
printf(" Current student address: %s
",student_list[a].saddress);
printf("Enter 1 to update & 0 to keep: "); scanf("%d",&up);
if (up==1)
	 {printf("Enter a new address: ");fflush(stdin); gets(student_list[a].saddress);}
printf("Successfully Update");
getchar();
}
}
}
void view(int i){
    int a;
    for (a=0;a<5;a++)
    printf("%s | %s | %s | %s | %s | %s |
",student_list[a].sid,student_list[a].sname,student_list[a].sdob,student_list[a].semail,student_list[a].sphone,student_list[a].saddress);
    if (i==0) printf("No data to show!
");
    getchar();
}
void del(int *i){
int test;
char del[8],x1[8],x2[8];
int u=0;
int c;
printf("Enter student ID: ");fflush(stdin); gets(del);
int a;
for (a=0;a<(*i);a++)
{
    strcpy(x1,student_list[a].sid);
    strcpy(x2,del);
    test = strcmp(strlwr(x1),strlwr(x2));
//a chinh la gia tri cua position trong mang
                if (test==0){
                                for ( c = a ; c < *i ; c++ )
                                    {strcpy(student_list[c].sid,student_list[c+1].sid);
                                     strcpy(student_list[c].sname,student_list[c+1].sname);
                                     strcpy(student_list[c].sdob,student_list[c+1].sdob);
                                     strcpy(student_list[c].semail,student_list[c+1].semail);
                                     strcpy(student_list[c].sphone,student_list[c+1].sdob);
                                     strcpy(student_list[c].saddress,student_list[c+1].saddress);}
                                 u++;
                                    {strcpy(student_list[*i].sid,del1);
                                     strcpy(student_list[*i].sname,del2);
                                     strcpy(student_list[*i].sdob,del2);
                                     strcpy(student_list[*i].semail,del2);
                                     strcpy(student_list[*i].sphone,del2);
                                     strcpy(student_list[*i].saddress,del2);}
                         }
}
if (u==0) printf("Student ID doesn't exist!");
getchar();
*i=*i-1;
}
void menu(){
    printf("		************************
");
    printf("		* 1. Add new student   *
");
    printf("		* 2. View all students *
");
    printf("		* 3. Search students   *
");
    printf("		* 4. Delete students   *
");
    printf("		* 5. Update student    *
");
    printf("		* 6. Exit              *
");
    printf("		************************
");
    printf("
");
}
int main(){
    int choice,i=0;
    g0:
    system("cls");
    menu();
//Kiem tra so nhap vao phai tu 1 den 6
    do {
    printf("Choose an option from 1 to 6: ");scanf("%d",&choice);}
    while (choice<1 || choice>6 && choice != 205);
    fflush(stdin);
    switch (choice){
        case 1: add(&i);
                break;
        case 2: view(i);
                break;
        case 3: search(i);
                break;
        case 4: del(&i);
                break;
        case 5: update(i);
                break;
        case 6: exit(0);
                break;
        case 205: 
        	printf("current i: %d",i); 
        	fflush(stdin); 
        	getchar();
        	break;
        default: ;
       
    }
    goto g0;
    getchar();
    return 0;
}
Pete Houston viết 02:42 ngày 01/10/2018

thật sự là code java?

Sáng Béo viết 02:42 ngày 01/10/2018

thật sự là code java?

bạn kia đang nhờ chuyển từ C qua Java mà a… code dài ghia… nhìn ngốt quá

Người bí ẩn viết 02:40 ngày 01/10/2018

Mình code bài tập này từ C giờ mình muốn chuyển nó sang java thi làm như thế nào vậy mấy bạn?

Thì học Java chứ làm gì nữa ?

Tynk Huynk viết 02:38 ngày 01/10/2018

Mới học Java thì học từ từ đi, vì mỗi khái niệm của ngôn ngữ này có thể giống ngôn ngữ kia, và trong suốt quá trình học bạn sẽ dần nắm bắt được. Và khi đó việc chuyển bài toán từ ngôn ngữ này qua ngôn ngữ kia sẽ không mấy khó khăn

Quân viết 02:40 ngày 01/10/2018

Chỉ mất công gõ thôi, java sang c++ mới đau đầu chứ c++ sang java thì có gì đâu

Reoteu Ray viết 02:41 ngày 01/10/2018

bài tập danh sách sinh viên , sang java dùng class thì làm vừa gọn vừa nhanh hơn c nhiều …

Bài liên quan
0