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

int main( int i Cin try t if(i throw out of range; throw system error; catch (logic error& e cout LE catch cout \"Unknown\" return 0 User enters 1: YOUR ANSWER HERE User enters 2 YOUR ANSWER HERE 2. What is wrong with the following exception-handling code? try Do whatever catch (exception& e Handle exception catch (logic error& e) Handle logic error catch (domain error& e) Handle out-of-range Suppose we have a project consisting of four files 3. main.cpp, Core.cpp utilities.cpp and tools.cpp There are two header files: core h includes declarations for functions in core.cpp tools h includes declarations for functions in both utilities.cpp and tools cpp ain .cpp uses functions fro core cpp and tools core.cpp uses functions from tilit pp and tool pp What #includes should be listed at the top of main.cpp? YOUR ANSWER HERE What #includes should be listed at the top of core.cpp? YOUR ANSWER HERE What commands do we give to compile this entire project into a single executable named \"core utilities\"? YOUR ANSWER HERE h of the foll th t belong pp) tat h) file header or both Function declaration YOUR ANSWER HERE Class definition: YOUR ANSWER HERE Method definition YOUR ANSWER HERE Function definition YOUR ANSWER HERE 5. On the server, there is a file located in \"/usr/share/dict/words\" that contains a dictionary of English words about 100,000 of them, one per line. rite a program which opens this file and counts the number of lines (words) in it YOUR ANSWER HERE

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;
}

C++ Introduction to Programming It is short and simple practice. Please solve #1,2,3,4,5 #include<iostream> ... Classes: members and methods Classes, cont
C++ Introduction to Programming It is short and simple practice. Please solve #1,2,3,4,5 #include<iostream> ... Classes: members and methods Classes, cont
C++ Introduction to Programming It is short and simple practice. Please solve #1,2,3,4,5 #include<iostream> ... Classes: members and methods Classes, cont

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site