C io - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

C io

Description:

radius of a circle, then calculates and prints its circumference and area. ... cout 'n The circumference of the circle is ' circ; ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 9
Provided by: cst137
Category:

less

Transcript and Presenter's Notes

Title: C io


1
C io10 parameters/File
  • CIS-161
  • Prof S.F. Gambino

2
Write a program that use a text file to input the
radius of a circle, then calculates and prints
its circumference and area. circ 2 radius
3.14 area 3.14 radius radius
  • Input......... Output......
  • Process.....

radius
circ
area
2 radius 3.14
circ
3.14 radius radius
area
3
Top down structured chart
4
  • include ltiostream.hgt
  • include ltfstream.hgt
  • include ltstdlib.hgt
  • include ltconio.hgt
  • include ltiomanip.hgt
  • // -------function prototypes--------
  • int getinput( ifstream , float )
  • void compute(float, float , float )
  • void Displayans(float, float, float)

5
Input......... radius text filefsInput
  • int getinput( ifstream fsInput , float radius
    )
  • fsInput
  • if ( !fsinput )
  • if ( fsInput.eof() )
  • return 0
  • else
  • cerr ltlt \n error.read
  • getch()
  • return 0
  • return 1

gtgt radius
6
Circ 2 radius 3.14 Area 3.14 radius
radius
  • void compute(float radius, float circ, float
    area )

circ 2 radius 3.14 area 3.14 radius
radius
7
Output......radius circ
area cout...
  • void Displayans (float radius, float circ, float
    area )
  • cout ltlt \n----------------------------------
    ----------------------

cout ltlt \n The radius of the circle is
ltlt radius
cout ltlt \n The circumference of the circle is
ltlt circ
cout ltlt \n The area of the circle is
ltlt area
8
  • void main()
  • float radius0, circ0, area0
  • ifstream fsInput
  • fsInput.open ( io10data.dat)
  • if ( !fsInput ) cerr ltlt \n error 100 open
    failed \n
  • getch()
  • exit(100)
  • while ( getinput( fsInput, radius ) )
  • compute ( radius,
    circ, area )
  • Displayans ( radius, circ, area )
  • fsInput.close()
  • if ( fsInput.fail() ) cerr ltlt \n error
    102 close failed \n
  • getch()

  • exit(102)
Write a Comment
User Comments (0)
About PowerShow.com