스택.. 좀 해결봐주세요 ..
엄지
질문 제목 :
구조체를 이용한 프로그램입니다..
3가지 중에 각 각소스로 이용해서 만들수있는 프로그램이 무엇인지..
질문 내용 :
프로젝트 1. 구조체를 이용한 성적처리프로그램 111111111111111#include
typedef struct
{
int id;
int kor, eng, math;
double tot, avg;
} ST1;
void main() {
int i;
ST1 ss[3];
for(i=0; i3; i++) {
scanf(%d%d%d, &ss[i].id, &ss[i].kor, &ss[i].math, &ss[i].eng);
ss[i].tot = ss[i].kor, ss[i].math, ss[i].eng;
ss[i].avg = ss[i].tot / 3;
}
printf(*****************************************************************************\n);
printf(번호 국어 영어 수학 총점 평균 등급\n);
printf(*****************************************************************************\n);
for(i=0; i3; i++) {
printf(%d %d %d %lf %lf, ss[i].kor, ss[i].math, ss[i].eng, ss[i].tot, ss[i].avg);
}
}
========================================================
2222222
메뉴 형식 - 1. 새파일 만들기
2. 파일 열기
3. 파일 저장
4. 종료파일 입출력 예제 샘플
#include stdio.h
int main() {
FILE *afp, *bfp;
char *fname=c.txt; // 파일 이름 선택
char ch;
afp=fopen(fname, w); //파일 이름
if(afp==NULL){
printf(a파일 개방 실패.\n);
return 1;
}
bfp=fopen(b.txt, a);
if(bfp==NULL){
printf(b파일 개방 실패.\n);
return 1;
}
printf(추가 데이터를 입력.\n);
while(1){
ch=getchar();
if(ch==EOF) break;
fputc(ch, bfp);
}
fclose(afp);
fclose(bfp);
return 0;
}
//////////////////////////////////////////////////////////
=== 메모장 =======
1. 파일 새로 열기
2. 기존 파일 열기
3. 종료
메뉴 선택#include stdio.h
#include stdlib.h
#include string.h
void display();
int new_File();
int file_open();
int modify(char *file_name);
int main() {
display();
return 0;
}
int new_file() {
FILE *newfp;
char ch;
char file_name[100]; // 파일 이름
printf(파일 이름 입력(ex: filename.txt) : );
scanf(%s, file_name);
newfp = fopen(file_name, w);
if(newfp == NULL) {
printf(%s 파일 열기 실패.\n, file_name);
return 1;
}
printf(%s 의 내용을 작성하세요.(내용 마무리는 EOF) \n\n, file_name);
while(1) {
ch=getchar();
if(ch==EOF) break;
fputc(ch, newfp);
}
printf(내용 완료 입니다. \n);
fclose(newfp);
system(cls);
display();
}
int file_open(){
FILE *existfp;
char ch;
char file_name[100]; // 파일 이름
printf(기존 파일 이름 입력(ex: filename.txt) : );
scanf(%s, file_name);
existfp = fopen(file_name, r);
if(existfp == NULL) {
printf(%s 파일 열기 실패.\n, file_name);
return 1;
}
while(1){
ch=fgetc(existfp);
if(ch==EOF) break;
putchar(ch);
}
fclose(existfp);
modify(file_name) ;
}
int modify(char *file_name) {
FILE *modifp;
char ch;
modifp = fopen(file_name, a);
if(modifp == NULL) {
printf(%s 파일 열기 실패.\n, file_name);
return 1;
}
/ printf(%s 의 추가 내용을 작성하세요.(마무리는 EOF) \n\n, file_name);
while(1) {
ch=getchar();
if(ch==EOF) break;
fputc(ch, modifp);
}
fclose(modifp);
display();
}
void display() {
int choice;
printf(=== 메모장 =======\n);
printf(1. 파일 새로 열기\n);
printf(2. 기존 파일 열기\n);
printf(3. 종료\n);
printf(메뉴 선택: );
scanf(%d, &choice);
switch(choice){
case 1: new_file();
break;
case 2:
file_open();
break;
case 3: exit(1);
break;
}
}
====================================================
333333333333 - 스택(배열 및 리스트) 구현
#include stdio.h
#include stdlib.h
#define STACK_SIZE 100
typedef int element; //int를 스택 element의 자료형으로 정의
element stack[STACK_SIZE];
int top= -1; //스택의 top의 초깃값을 -1로 설정
void push(element item) //스택의 삽입 연산
{
if(top = STACK_SIZE-1) { //스택이 이미 Full인 경우
printf(\n\n Stack is FULL ! \n);
return;
}
else stack[++top]=item;
}
element pop() //스택의 삭제 후 반환 연산
{
if(top==-1) { //현재 스택이 공백인 경우
printf(\n\n Stack is Empty!!\n);
return 0;
}
else return stack[top--];
}
void del() //스택의 삭제 연산
{
if(top==-1) { //현재 스택이 공백인 경우
printf(\n\n Stack is Empty !\n);
exit(1);
}
else top--;
}
element peek() //스택의 top 원소 검색 연산
{
if(top==-1){ //현재 스택이 공백인 경우
printf(\n\n Stack is Empty !\n);
exit(1);
}
else return stack[top];
}
void printStack() //스택 내용 출력 연산
{
int i;
printf(\n STACK [ );
for(i=0; i=top; i++)
printf(%d ,stack[i]);
printf(] );
}
void main(void)
{
int item;
printStack();
push(1);
printStack();
push(2);
printStack();
push(3);
printStack();
push(4);
printStack();
push(5);
printStack();
push(6);
printStack();
item = peek();
printStack();
printf(peek top = %d, item);
del();
printStack();
item = pop();
printStack();
printf(\t pop top = %d, item);
item = pop();
printStack();
printf(\t pop top = %d, item);
item = pop();
printStack();
printf(\t pop top = %d, item);
item = pop();
printStack();
printf(\t pop top = %d, item);
pop();
getchar();
}도와주십시오.. 제머리로는 불가능입니다..