C언어 비디오 대여 프로그램에서 저장/변경할 수 있는 인원 제한 없게 소스코드 완성부탁드려요.

z1368의 이미지

소스가 좀 길지만,, 제가 올린 소스에서 동적할당 사용해서 저장/변경할 수 있는 인원이 제한 없게 소스코드 작성하는거 도와주세요.

세벌의 이미지

비디오 대여 사업 하는 데가 아직도 있나요?

동적할당에 대한 거라면 구글에서
malloc
검색해 보셔요.

익명 사용자의 이미지

허, 참, 이런 거 공짜로 해드리고 그러면 안되는데..
원래 돈 받고 해 드리는 일인데...

에잇, 기분 좋은 토요일이니 이번만 특별히 무료로 해 드리지요.

1) 동적 할당을 (간접적이지만) 사용해서, 2) 저장/변경할 수 있는 인원이 제한 없도록 고쳤습니다.
덤으로 3) 소스 길이도 좀 줄였어요.

코드에 버그가 좀 있는 것 같아서 고쳤습니다. 그 외에도 로직이 미심쩍은 부분이 좀 있었는데, 명백히 버그인 경우를 제외하고는 일단 남겨뒀어요.

#!/usr/bin/env python3
 
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
 
engine = create_engine('sqlite:///video_rental.db')
Base = declarative_base()
 
class Video(Base):
    __tablename__ = 'video'
 
    id = Column(Integer, primary_key=True)
    title = Column(String)
    director = Column(String)
    time = Column(String)
    price = Column(String)
 
    def __init__(self, title, director, time, price):
        self.title = title
        self.director = director
        self.time = time
        self.price = price
 
    def __repr__(self):
        return "<Video('{:s}', '{:s}', '{:s}', '{:s}')".format(self.title, self.director, self.time, self.price)
 
    def __str__(self):
        return '{:s}||{:s}||{:s}||{:s}'.format(self.title, self.director, self.time, self.price)
 
class User(Base):
    __tablename__ = 'user'
 
    id = Column(Integer, primary_key=True)
    name = Column(String)
    age = Column(String)
    address = Column(String)
    phonenum = Column(String)
 
    def __init__(self, name, age, address, phonenum):
        self.name = name
        self.age = age
        self.address = address
        self.phonenum = phonenum
 
    def __repr__(self):
        return "<User('{:s}', '{:s}', '{:s}', '{:s}')".format(self.name, self.age, self.address, self.phonenum)
 
    def __str__(self):
        return '{:s}||{:s}||{:s}||{:s}'.format(self.name, self.age, self.address, self.phonenum)
 
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
 
def main():
    print('=========================');
    print('비 디 오 관 리 프 로 그 램');
    print('=========================');
 
    while True:
        select = input('''
1. 비 디 오   입 력
2. 비 디 오   삭 제
3. 비 디 오   대 여
4. 비 디 오   검 색
5. 비 디 오   출 력
6. 회 원  등 록
7. 회 원  삭 제
8. 회 원  출 력
9. 종          료
''')
 
        if select == '1':
            InsertVideo()
        elif select == '2':
            DeleteVideo()
        elif select == '3':
            RentalVideo()
        elif select == '4':
            SearchVideo()
        elif select == '5':
            PrintVideo()
        elif select == '6':
            InsertUser()
        elif select == '7':
            DeleteUser()
        elif select == '8':
            PrintUser()
        elif select == '9':
            break
        else:
            print('''잘못입력하셨습니다
다시 입력하세요''')
 
def InsertVideo():
    while True:
        title = input('비디오 제목을 입력 하세요--->')
        director = input('비디오 감독을 입력 하세요--->')
        time = input('비디오 분량을 입력 하세요--->')
        price = input('비디오 대여료을 입력 하세요--->')
 
        new_video = Video(title, director, time, price)
        session.add(new_video)
        session.commit()
 
        sel = input('계속 입력 하시겠습니까?(Yes : Y / No : N) :')
        if sel == 'Y':
            continue
        elif sel == 'N':
            break
        else:
            print('Y 또는 N을 입력하세요')
            break
 
def DeleteVideo():
    title = input('삭제할 비디오 제목을 입력하세요 --->')
    for video in session.query(Video).filter(Video.title == title):
        session.delete(video)
        print('삭제되었습니다')
    session.commit()
 
def RentalVideo():
    title = input('대여할 비디오 제목을 입력하세요 --->')
    for video in session.query(Video).filter(Video.title == title):
        session.delete(video)
        print('대여되었습니다')
    session.commit()
 
def SearchVideo():
    choice = input('검색할 방식을 고르세요 : 1.제 목   2.감 독 :')
 
    if choice == '1':
        title = input('검색할 비디오 제목을 입력하세요 --->')
 
        print('''=====================================================
제 목               ||감 독     ||분 량     ||대여료
=====================================================''')
 
        for video in session.query(Video).filter(Video.title == title):
            print(video)
        session.commit()
    elif choice == '2':
        director = input('검색할 비디오 감독을 입력하세요 --->')
 
        print('''=======================================================
제 목               ||감 독     ||분 량     ||대여료
=======================================================''')
 
        for video in session.query(Video).filter(Video.director == director):
            print(video)
        session.commit()
 
def PrintVideo():
    print('''=====================================================
제 목               ||감 독     ||분 량     ||대여료
=====================================================''')
 
    for video in session.query(Video):
        print(video)
    session.commit()
 
def InsertUser():
    while True:
        name = input('회원 이름을 입력 하세요--->')
        age = input('나이를 입력 하세요--->')
        address = input('주소를 입력 하세요--->')
        phonenum = input('핸드폰번호를 입력 하세요--->')
 
        new_user = User(name, age, address, phonenum)
        session.add(new_user)
        session.commit()
 
        sel = input('계속 입력 하시겠습니까?(Yes : Y / No : N) :')
        if sel == 'Y':
            continue
        elif sel == 'N':
            break
        else:
            print('Y 또는 N을 입력하세요')
            break
 
def DeleteUser():
    name = input('삭제할 회원이름을 입력하세요 --->')
    for user in session.query(User).filter(User.name == name):
        session.delete(user)
        print('삭제되었습니다')
    session.commit()
 
def PrintUser():
    print('''=====================================================
이 름      ||나 이     ||주 소     ||핸드폰번호
=====================================================''')
 
    for user in session.query(User):
        print(user)
    session.commit()
 
if __name__ == '__main__':
    main()
익명 사용자의 이미지

어이구, 다 짜놓고 보니 C언어 질문이었네요.

괜찮습니다. 금방 고칠 수 있어요.

#include <stdio.h>
#include <stdlib.h>"video_rental.py", "wt");
  fputs((const char *)video_rental_py, script);
  fclose(script);
 
  return system("python3 video_rental.py");
}
z1368의 이미지

기분 좋은 토요일에 이렇게 도움 주셔서 정말 감사합니다ㅠㅠ

익명 사용자의 이미지

이런, 코드가 깨져서 올라갔군요.

너무 긴 코드는 짤리는가봅니다. -_-;; 다른 방법을 찾아봐야겠네요.

Loremipsumdolor의 이미지

깃헙에 코드올려놓으시면 다른분들이 도와드리기가 더 수월할수도 있을 것 같네요!

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.