In: Computer Science
c++ programming
int numbers[4]={99,87};
cout<<numbers[3]<<endl;
double mylist[5];
for(int i=0; i<5; i++)
mylist[i]= (pow(i,2)+ 1 /2.0;
cout<<fixed<<showpoint<<setprecision(2);
for(int i=0; i<5; i++)
{ cout<<setw(5)<<mylist[i];
}
a. .5 1.5 4.5 9.5 16.5
b. 0.50 1.50 4.50 9.50 16.50
c. 0.50 1.50 8.50 27.50 64.50
d. 0.50 1.50 2.50 3.50 4.50
15. what is stored in list after the following C++ statement is executed?
int list [8];
list[0]=1;
list[1]=2;
for(int i=2; i<7; i++)
{
list[i]= list[i-1] * list[i-2];
cout<<setw(5)<<list[i];
}
int i;
int list [8];
list[0]=1;
list[1]=2;
for(int i=2; i<7; i++)
{
list[i]= list[i-1] * list[i-2];
cout<<setw(5)<<list[i];
}
for(int i=2; i<7; i++)
{
if( i>3)
list[i]= list[i]- list[i-1];
cout<<setw(5)<<list[i];
}
a. 2 4 16 32 256 2 4 8 28 228 b. 2 4 4 16 256 2 4 4 28 228
c. 2 4 8 32 256 2 2 4 28 228 d. 2 4 8 32 256 2 4 4 28 228
Given int numbers[]= { 12,145,567,100,1001};
Given:
struct nameType { string first_name; string last_Name; string middle_Name; };
struct addressType { string address; string city; string state; string zip; };
struct courseType { string course_Name; int course_number; string major; };
struct dateType { int month; int day; int year; };
struct studentType { nameType name; int student_ID; addressType address; dateType enrolled;};
studentType student;
studentType array[89];
courseType course;
nameType name;
student.gpa=4.0;
student.name.first_name="Robert";
student.course.course_Name="Chem";
array[0].enrolled=student.enrolled;
array[1].name.first_name="Jane";
studentType student;
studentType array[89];
courseType course;
nameType name;
student.gpa=4.0;
student.name="Robert";
student.course.="Chem";
array[0].enrolled=student.enrolled;
array[1].name.first_name="Jane";
Question 1:
   int numbers[4] = {99,87};
   cout<<numbers[3]<<endl;
   As numbers[3] is not set so it will 0.
   ans: option B
   0
Question 2:
   double mylist[5];
   for(int i=0; i<5; i++)
   {
       mylist[i]= (pow(i,2)+ 1
/2.0);
       when any of the divisor or dividend
is float then division is complete division.
       1st loop i=0 mylist[0] = 0 + 1/2.0
= 0.50
       2nd loop i=1 mylist[1] = 1 + 1/2.0
= 1.50
       3rd loop i=2 mylist[2] = 2 power 2
+ 1/2.0 = 4 + 1.50 = 4.50
       4th loop i=3 mylist[3] = 3 power 2
+ 1/2.0 = 9.50
       5th loop i=4 mylist[4] = 4 power 2
+ 1/2.0 = 16.50  
   }
   ans: option b
   0.50 1.50 4.50 9.50 16.50
  
Question 3:
   ans: option d
   2 4 8 32 256
  
Question 4:
   ans: option d
   d. 2 4 8 32 256 2 4 4 28 228
  
Question 5:
  
#include<bits/stdc++.h>
using namespace std;
int highest(int arr[], int n) 
{ 
    int i; 
    int max = arr[0];  
    for (i = 1; i < n; i++) 
        if (arr[i] > max) 
            max = arr[i]; 
    return max; 
} 
int main()
{
    int numbers[]= { 12,145,567,100,1001};
    int n = sizeof(numbers) / sizeof(numbers[0]); 
    cout << "Largest element given array is "<< highest(numbers, n);
    return 0; 
}
Output:
