Vous êtes sur la page 1sur 1

EEIT-2015

High-Level Programming Language


Exercises: C++ Programming Language
Exercises 12:
Write a CPP function intcount_number_of_line(char *path) using ifstream to read a file, print
to console line by line and return the number of lines. The function should throw an error if the
filename is incorrect. This error must be caught in main program.
Test this functionin main(). User can input the filename, then use the function above to get
number of line inside that file.
Hint :
ifstreaminput_stream(path);
input_stream.is_open() // check if file is open ok if ok it return true
cin.getline(path,limit_size) // get line from input

Exercise 13:

Write a definition of a Vector3D classthat represents3-dimensional. This class has 3protected


double attributes x,y,zrepresenting itscoordinate , each of whichhas a defaultof 0 (implemented
in constructor). It has at least some member functions below:
Set3D(double x,doubley,double z)to set the coordinate attributes of class
print_info () to print out the length of this vector and the x,y,z coordinate.
getX() , getY() , getZ() to read out the value coordinate X,Y,Z
get_abs() to get the length of this vector

Implement the Overloaded operators ( assume that we declare Vector3D a ,b,c)


Operator + : to sum two vector ( c = a+b)
Operator - : to subtract two vector (c = a-b)
Operator * : to cross product two vector (c = a^b)
For example
Vector3Da(2, 4, 6);//declare vector a = (2,4,6)
Vector3Db(12, 2, 3);//declare vector b = (12 ,2,3)
Vector3D c;
c.print_info();
c = a + b;;//do operator plus two vector
c.print_info();//print_out result
Test the class Vector3Din main(), demonstrate that all member functions work as specified

Exercises 14:

Write a CPP program that sorts a list of Vector3D elementsby vector lengthusing bubble sort
algorithm(ascending or descending order , can choose one). Vector3D class is defined in
Exercise 13. User can input the number of elements in the list, then the program asks them to
input x,y,z of each elements until reaching the end of list. After that do sorting and print the
result.

Vous aimerez peut-être aussi