You are on page 1of 5

CS100 Computational Problem Solving

Fall 2022-23
Section 3 Friday, 9 Sept 2022
Homework: Week-1
Solution

Theory Questions:
Q 1) What task does a compiler perform?

Ans) The compiler translates the source code into machine code and creates an object file

Q 2) What type of language is C++


a) Machine language
b) Assembly language
c) High Level Language
d) English Language

Q 3) What does this program print?

#include <iostream>

using namespace std;

int main()

cout << "Hello" << endl << "World" << endl;

cout<< “Hello”;

cout<< “World”;

return 0;

}
Ans) Output:

Hello

World

HelloWorld

Q 4) What does this program print?


#include <iostream>
using namespace std;
int main() {
cout << "Hello" << "World" << endl;
return 0;
}
Pay close attention to spaces.
Output:
HelloWorld

Q 5) What does this command line instruction performs?


g++ file.cpp -o run_file
a ) It runs the code saved in file
b ) It compiles the code in file and produces an executable file
c ) It quits the program
d ) It creates a hello world program

Q 6) What services does the following header provides for the program
#include <iostream>
Ans) It provides input and output services.

Q 7) What is wrong with the program:


#include <iostream>
using namespace std;
int main() {
cout << "Hello World" << endl;
}
Ans) it is missing a
return 0;
statement at the end

Programming Questions:
Q 1) Print your name using “*”.
Sample output
Ans)

#include <iostream>

using namespace std;

int main()
{

cout << "* * ****** *" << endl;


cout << "* * * *" << endl;
cout << "* * * * ****** *" << endl;
cout << "* * * *" << endl;
cout << "* * ****** *******";
}

Q 2) Print Hello in three different languages. Sample output:

Ans)

#include <iostream>

using namespace std;

int main()

cout << "Hello" << endl;

cout << "Bonjour" << endl;

cout<<”Hola”<<endl;

return 0;

}
Q 3) Print the following sample output:

Ans)

#include <iostream>
using namespace std;

int main()
{
cout << "#" << endl;
cout << "##" << endl;
cout << "###" << endl;
cout << "####" << endl;
cout << "#####" << endl;
cout << "######" << endl;
}

You might also like