You are on page 1of 3

A) Dynamic Memory Allocation

1) Write a program to ask for sales figures for any number of days. The figures are
stored in a dynamically allocated array and then calculate the total and the average.

Sample run:

2) Use a dynamic array to write a program that allows the user to enter the names of
five candidates in a local election and the number of votes received by each
candidate. The program should then output each candidate’s name, the number of
votes received, and the percentage of the total votes received by the candidate. Your
program should also output the winner of the election. A sample output is:

Sample run:

B) Namespaces
1) What is wrong with the following program?

#include<iostream>
Without
int main() using namespace std;
{
cout<<"Hello XMUM!"<<endl;
return 0;
}

2) What is wrong with the following program?

#include<iostream>
namespace function1
{
const int X=0;
double y; using namespace function1;
}
using namespace std;
int main()
{
y=12.345; y and X is in function 1
cout<<"X = "<<X<<", y = "<<y<<endl;
add function1:: in front
return 0; of y and X
}

3) What is the output produced by the following program?

#include <iostream>
using namespace std;
namespace sof103
{
void message( )
{
cout << "Hello from SOF103.\n";
}
}
namespace
{
void message( )
{
cout << "Hello from unnamed.\n";
}
}
int main( )
{
{
message( ); Hello from unnamed
using sof103::message; Hello from SOF103
message( );
}
message( ); Hello from unnamed
return 0;
}

You might also like