Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Q9: What is the output of the following program:
- #include <iostream>
- using namespace std;
- int main() {
- int a[] = { 6,1,6,3,1,4,5,6,4,7 };
- for (int i = 0; i < 10; i++)
- {
- }
- bool found = false;
- for (int j = i - 1; j >= 0; j--)
- if (a[j] == a[i])
- found = true;
- if (!found)
- cout << a[i] << endl;
- return 0; }
- Q10: What is the output of the following program:
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- ifstream inputFile;
- inputFile.open("numbers.txt");
- int v1 = 0, number;
- while (inputFile >> number)
- v1 += number;
- cout<<v1 << endl;
- return 0; }
- The content of numbers.txt file is “1 2 3 4 5” Q11: What is the output of the following program:
- #include <iostream>
- using namespace std;
- void function1(int n)
- {
- while (n > 0) {
- cout << n % 2;
- n = n / 2;
- }
- cout << endl;
- }
- int main() {
- function1(10);
- return 0; }
- . Q12: What is the output of the following program:
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- ifstream inputFile;
- inputFile.open("numbers.txt");
- int n,t=0;
- for (int i = 0; i < 5; i++)
- {
- inputFile >> n;
- t += n; }
- cout<< t/5.0 << endl;
- return 0; }
- The content of numbers.txt file is 1
- 2
- 3
- 4 5
- Q13: What is the output of the following program:
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- }
- struct Distance
- {
- int Meters;
- int Centimeters;
- };
- Distance d1 = {20,90};
- Distance d2 = { 10, 14 };
- Distance dResult;
- dResult.Centimeters = d1.Centimeters + d2.Centimeters;
- dResult.Meters = d1.Meters + d2.Meters;
- if (dResult.Centimeters >= 100)
- {
- dResult.Centimeters -= 100;
- dResult.Meters++;
- }
- cout << dResult.Meters << '.' << setw(2) << setfill('0')
- << dResult.Centimeters << "." << endl;
- return 0;
- 8
- Q14: What is the output of the following program:
- #include <iostream>
- using namespace std;
- int main()
- {
- int a[] = { 2,6,2,3,6,4,5,6,4,7 };
- for (int i = 0; i < 10; i++)
- {
- }
- int count = 0;
- bool found = false;
- for (int j = 0; j < 10; j++)
- if (a[j] == a[i])
- if (j >= i)
- count++;
- else
- {
- found = true;
- break; }
- if (!found)
- cout << "value: " << a[i] << "\tcount= " << count << endl;
- return 0; }
- . Q15: What is the output of the following program:
- #include <iostream>
- #include <string>
- using namespace std;
- struct student
- {
- int id;
- string name;
- int grades[6];
- };
- double doSomething(int a[])
- {
- int t = a[0];
- for (int i = 1; i < 6; i++)
- if (a[i] > t)
- t = a[i];
- return t; }
- int main() {
- student s1 = { 101,"Mohamed",{90,80,70,95,85,88} };
- student s2 = { 102,"Ahmed",{ 90,70,60,85,75,68 } };
- student s3 = { 103,"Naer",{ 92,90,50,75,65,78 } };
- cout << "ID\tName\tAverage" << endl;
- cout << s1.id << "\t" << s1.name << "\t" << doSomething(s1.grades) << endl; cout << s2.id << "\t" << s2.name << "\t" << doSomething(s2.grades) << endl; cout << s3.id << "\t" << s3.name << "\t" << doSomething(s3.grades) << endl; return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement