C Introduction to Programming It is short and simple practic
C++ Introduction to Programming
It is short and simple practice.
Please solve #1,2,3,4,5
#include<iostream>
...
Classes: members and methods
 Classes, continued: access specifiers and constructors
 Classes for object oriented design
 Recursion
 Multi-file projects and header files
 Exceptions, tests, and assertions
 Assertions, Advanced Input/Output
 Operator Overloading; Inheritance and Abstract data types
Solution
1.
#include <iostream>
 #include <string>
int main()
 {
 int i;
 std::cin>>i;
   
 try{
 if(i == 1)
 throw \"out_of_range\";
 else
 throw \"system_error\";
 }catch(std::logic_error &e){
        std::cout<<\"ok\";
 }catch(...){
 std::cout<<\"Unknown\";
 }
 return 0;
 }
USER ENTER 1 : Unknown
USER ENTER 2 : Unknown
2.
try{
// do whatever
}catct(Exception &e){
// handle exception
}
catct(logic_error &e){
// handle logic error exception
}
catct(domain_error &e){
// handle domain error exception
}
Ans: Always catch block eith exception will execute because exception is the super class of the logic_error and domain_error classes.So we should write catch block with exception at the end of the catch block.
3.
what #includes should be listed at the top of main.cpp?
Ans: #iinclude<iostream>
#include \"core.cpp\"
#include \"tools.cpp\"
what #includes should be listed at the top of core.cpp?
Ans: #iinclude<iostream>
#include<core.h>
#include \"tools.cpp\"
#include \"utilities.cpp\"
4. Function declaration : Header file
Class definition : Source file.
Method definition : Source file.
Function definition : Header file
5.
code:
#include<iostream>
 #include<fstream>
using namespace std;
int main() {
ifstream myReadFile;
 myReadFile.open(\"words.txt\");
 char output[100];
 int count=0;
 if (myReadFile.is_open()) {
 while (!myReadFile.eof()) {
 myReadFile >> output;
    count++;
 }
 }
 myReadFile.close();
 cout<<\"Number of lins(words):\"<<count;
 return 0;
 }



