Join the forum, it's quick and easy

Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.
Similar topics
Tìm kiếm
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» [GIÚP ]KÍCH HOẠT Ở ĐÂU THÌ KHI COPY EMBED CODE SẼ HIỆN THỊ VIDEO TRÊN FORUMVI?
File (phanso.inp---->phanso.out EmptyTue May 21, 2013 8:07 am by NGUOIMIENTAY

» THAY ĐỔI HÌNH ẢNH TRÊN DIỄN ĐÀN ĐI XẤU QUÁ HÀ
File (phanso.inp---->phanso.out EmptySat Feb 04, 2012 8:36 pm by hongsang

» KỸ NĂNG ĐẠT ĐẾN THÀNH CÔNG - BIẾT CÁCH BÁN HÀNG
File (phanso.inp---->phanso.out EmptySat Sep 24, 2011 2:05 pm by banhminuong

» Source BT tuần 1
File (phanso.inp---->phanso.out EmptySun Sep 18, 2011 7:44 pm by nucuoithienthan20077

» 12 Lý do để thử ngay Ubuntu 11.04
File (phanso.inp---->phanso.out EmptySat Sep 17, 2011 9:57 pm by fx

» Bài tập SINHVIEN
File (phanso.inp---->phanso.out EmptyWed Sep 14, 2011 10:15 pm by fx

» Bom Tan Tuan` 1 ne````
File (phanso.inp---->phanso.out EmptyMon Aug 29, 2011 1:11 pm by nucuojhanhphuc

» TÀI LIỆU KIẾN TRÚC MÁY TÍNH
File (phanso.inp---->phanso.out EmptyMon Aug 29, 2011 12:41 am by minhduc2592

» ĐÔRÊMON CHẾ
File (phanso.inp---->phanso.out EmptySat Aug 13, 2011 11:31 am by nucuoithienthan20077

Top posters
fx (49)
File (phanso.inp---->phanso.out I_vote_lcapFile (phanso.inp---->phanso.out I_voting_barFile (phanso.inp---->phanso.out I_vote_rcap 
thanhvu215 (19)
File (phanso.inp---->phanso.out I_vote_lcapFile (phanso.inp---->phanso.out I_voting_barFile (phanso.inp---->phanso.out I_vote_rcap 
minhduc2592 (13)
File (phanso.inp---->phanso.out I_vote_lcapFile (phanso.inp---->phanso.out I_voting_barFile (phanso.inp---->phanso.out I_vote_rcap 
nucuoithienthan20077 (7)
File (phanso.inp---->phanso.out I_vote_lcapFile (phanso.inp---->phanso.out I_voting_barFile (phanso.inp---->phanso.out I_vote_rcap 
biboy (6)
File (phanso.inp---->phanso.out I_vote_lcapFile (phanso.inp---->phanso.out I_voting_barFile (phanso.inp---->phanso.out I_vote_rcap 
pengox2912 (2)
File (phanso.inp---->phanso.out I_vote_lcapFile (phanso.inp---->phanso.out I_voting_barFile (phanso.inp---->phanso.out I_vote_rcap 
boylangyeu (2)
File (phanso.inp---->phanso.out I_vote_lcapFile (phanso.inp---->phanso.out I_voting_barFile (phanso.inp---->phanso.out I_vote_rcap 
sock (2)
File (phanso.inp---->phanso.out I_vote_lcapFile (phanso.inp---->phanso.out I_voting_barFile (phanso.inp---->phanso.out I_vote_rcap 
nucuojhanhphuc (2)
File (phanso.inp---->phanso.out I_vote_lcapFile (phanso.inp---->phanso.out I_voting_barFile (phanso.inp---->phanso.out I_vote_rcap 
nhongthuy (2)
File (phanso.inp---->phanso.out I_vote_lcapFile (phanso.inp---->phanso.out I_voting_barFile (phanso.inp---->phanso.out I_vote_rcap 

May 2024
MonTueWedThuFriSatSun
  12345
6789101112
13141516171819
20212223242526
2728293031  

Calendar Calendar

Lick chuột vào đây chat cho vui!
Admin File (phanso.inp---->phanso.out Anhso-09641_lc01171151911 Không có tạ! Mình dùng tạm cái này vậy!!

File (phanso.inp---->phanso.out

 :: C++ :: Bài tập KTLT

Go down

File (phanso.inp---->phanso.out Empty File (phanso.inp---->phanso.out

Bài gửi by fx Sat May 21, 2011 1:00 pm

BT8-1. Viết chương trình đọc file “phanso.inp”, thông tin của file “phanso.inp” được mô tả như sau:
o Dòng đầu tiên là một số nguyên n (n là số lượng các phân số)
o n dòng tiếp theo là n phân số, một phân số bao 2 phần: tử số và mẫu số, giữa tử số và mẫu số cách nhau đúng một khoảng trắng (xem file “phanso.inp”.
Viết chương trình đọc file “phanso.inp” và xuất ra màn hình nội dung của các phân số tăng dần theo giá trị đồng thời ghi xuống file “phanso.out”.
Code:

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
struct PhanSo{
   int tu;
  int mau;
};
typedef struct PhanSo PS;
int DocFile(char *fn,PS a[],int &n)
{
   FILE *f;
  f=fopen(fn,"rt");
  if(f==NULL)
   return 0;
  fscanf(f,"%d",&n);
   for(int i=0;i<n;i++)
  {
      fscanf(f,"%d",&a[i].tu);
      fscanf(f,"%d",&a[i].mau);
  }
  fclose(f);
  return 1;
}
void HoanVi(PS &a,PS &b)
{
   PS t;
  t=a;
  a=b;
  b=t;
}
void SapTang(PS a[],int n)
{
   for(int i=0;i<n-1;i++)
   for(int j=i+1;j<n;j++)
   if((a[i].tu/a[i].mau)>(a[j].tu/a[j].mau))
      HoanVi(a[i],a[j]);
}
int GhiFile(char *fn,PS a[],int n)
{
   FILE *f;
  f=fopen(fn,"wt");
  if(f==NULL)
      return 0;
  for(int i=0;i<n;i++)
  {
   fprintf(f,"%d%4d",a[i].tu,a[i].mau);
      fprintf(f,"\n");
  }
  fclose(f);
  return 1;
}
void main()
{
   clrscr();

  PS a[100];
  int n;
  int df;
  df=DocFile("phanso.inp",a,n);
  if(df==0)
   cout<<"\nLoi doc file";
  else
  {
   cout<<"\nDoc file thanh cong";
      SapTang(a,n);
      int gf=GhiFile("phanso.out",a,n);
      if(gf==0)
   cout<<"\nLoi ghi file";
      else
   cout<<"\nGhi file thanh cong";
  }
  getch();
}

fx
fx
Admin

Tổng số bài gửi : 49
Points : 179
Reputation : 3
Join date : 02/04/2011
Age : 31

https://04cdct1.forumvi.com

Về Đầu Trang Go down

Về Đầu Trang

- Similar topics

 :: C++ :: Bài tập KTLT

 
Permissions in this forum:
Bạn không có quyền trả lời bài viết