0% found this document useful (0 votes)
26 views9 pages

CBCA108 2024 Even Week1

The document outlines the exam details for the course 'Data Structures: Concepts and Practice' including the exam pattern, total marks, and allowed programming languages. It contains programming questions in C++ with problem statements, input/output formats, and sample solutions for each question. The questions cover basic programming concepts such as printing strings, variable types, and implementing a shopping list using classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views9 pages

CBCA108 2024 Even Week1

The document outlines the exam details for the course 'Data Structures: Concepts and Practice' including the exam pattern, total marks, and allowed programming languages. It contains programming questions in C++ with problem statements, input/output formats, and sample solutions for each question. The questions cover basic programming concepts such as printing strings, variable types, and implementing a shopping list using classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Question Paper

Exam Details

● Course Name: Data Structures: Concepts and Practice


● Course Code: CBCA108
● Exam Name: CBCA108-2024-Even-Week1
● File Name: CBCA108-2024-Even-Week1

Exam Pattern

● Number of Sections: 1
● Total Marks: 20
● Marks per Question:
○ Section 1: Display all questions, each worth 10 marks (10 = marks)
○ Section 2: Display 2 out of 2 questions, each worth 20 marks (2 * 20 = 40
marks)
● Total Duration: 2 hours
● Allowed Programming Languages: C++
● Partial Marking: Enabled

Section 1: Basic Programming Questions (10 marks each)

Question 1: Write a C++ program to print a string without using ‘namespace std’

● Problem Statement: Write a C++ program to print a string without using ‘namespace
std’
● Input Format: None
● Output Format:
○ A string that user wants to print.
● Hints: None

Solution:

#include <iostream>

int main()

std::cout<< “This is my first C++ Program”<<std::endl;

return 0;

Test Cases:
Input Output Weightage Visibility

This is my first C++ 50% Visible


Program

Hello 25% Visible

How are you 25% Hidden

Question 2: Variable Types

● Problem Statement: Write a C++ program to print the size of int, char, float and
double type variables
● Constraints: None
● Input Format: None
● Output Format:
○ Print the size of size of int, char, float and double type variables
● Hints: None

Solution:
#include <iostream>
using namespace std;
int main()
{
int x;
char c;
double d;
float f;
cout << sizeof(x) << endl;
cout << sizeof(c) << endl;
cout << sizeof(f) << endl;
cout << sizeof(d) << endl;

Test Cases:
Input Output Weightage Visibility

2 100% Visible
1
4
8

Question 3:
● Problem Statement: Write a C++ program where you take a sentence as an input
from the user and output each word of a sentence in a separate line

● Constraints: None
● Input Format: A srting
● Output Format:
○ Print each word of a line in new line.
● Hints: None

Solution:
#include <iostream>
using namespace std;
int main()
{
char str[100];
int i = 0; cin.getline(str,100);
while(str[i] != '\0')
{
if(str[i] == ' ')
cout << endl;
else
cout << str[i];
i++;
}
}
Test Cases:
Input Output Weightage Visibility

This is a program to get This 50% Visible


the idea of control is
statements a
program
to
get
the
idea
of
control
statements

Hello how are you Hello 25% Hidden


how
Are
you

We are studying We 25% Hidden


Programming Language Are
studying
Programming
Language

Question 4:

● Problem Statement: Write a C++ program to sum the series.

Constraints: None
● Input Format: user have to insert two positive number for X and n values
● Output Format:
○ Print the sum of series.
● Hints: None

Solution:
#include <iostream>
#include<math.h>

using namespace std;

int main()
{
int x;
int n;
double sum = 1, term = 1, fct, j, y = 2, m;
cin>> x;
cin>>n;
// Sum of n-1 terms starting from 2nd term
int i;
for (i = 1; i < n; i++)
{
fct = 1;
for (j = 1; j <= y; j++)
{
fct = fct * j;
}
term = term * (-1);
m = term * pow(x, y) / fct;
sum = sum + m;
y += 2;
}
cout<<sum ;
return 0;
}
Test Cases:
Input Output Weightage Visibility

7 1 25% Visible
1

4 3.66667 25% Visible


3

5 2.5284 25% Hidden


5

7 -23.5 25% Hidden


2

Question 4:

● Problem Statement: A shopkeeper wants to process a shopping list for his


depatrmental store. The list include details such as the Code No and Price of each
item and perform the operations like Adding, Deleting Items to the list and Printing
the Total value of a Order. Write a Program using class to process Shopping List.

Constraints: None
● Input Format: Users have to choose the actions from the menu
● Output Format:
Hints: class ITEMS
{
int
itemCode[m
]; float
itemPrice[
m]; int
count;
public:
void CNT(void)
{count=0;} void
getitem(void);
void
displaySum(void)
; void
remove(void);
void displayItems(void);
};
It should be a menu based program:

cout<<"\n You can do the following;"


<<"Enter appropriate number\n";
cout<<"\n1 : Add an Item";
cout<<"\n2 : Display Total Value";
cout<<"\n3 : Delete an Item";
cout<<"\n4 : Display all items";
cout<<"\n5 : Quit";
Solution:
#include<iostream>
using namespace std;
const int m=50;
class items
{
int itemcode[m];
float itemPrice[m];
int count;
public:
void CNT()
{
count = 0;
}
void getitem();
void display();
void displaysum();
void remove();
void displayItems();
};
void items :: getitem()
{
cout<<"Enter item code :";
cin>>itemcode[count];
cout<<"Enter item cost :";
cin>>itemPrice[count];
count++;
}
void items :: displaysum()
{
float sum =0;
for(int i=0;i<count;i++)
{
sum = sum+itemPrice[i];
}
cout<<"\nTotal Value :"<<sum<<"\n";;

}
void items :: remove()
{
int a;
cout<<"Enter item code: ";
cin>>a;
for(int i=0;i<count;i++)
if(itemcode[i] == a)
itemPrice[i] = 0;
}
void items :: displayItems()
{
cout<<"\n Code Price\n";
for(int i=0;i<count;i++)
{
cout<<"\n"<<itemcode[i];
cout<<" "<<itemPrice[i];
}
cout<<"\n";
}
int main()
{
items order;
order.CNT();
int x;
do{
cout<<"\n you can do the following:";
cout<<"Enter Appropriate number \n";
cout<<"\n1 : Add an item";
cout<<"\n2 : Display Total Value";
cout<<"\n3 : Delete an item";
cout<<"\n4 : Display all items";
cout<<"\n5 : Quit";
cout<<"\n\n Choice : ";
cin>>x;
switch(x)
{
case 1:
order.getitem();
break;
case 2:
order.displaysum();
break;
case 3:
order.remove();
break;
case 4:
order.displayItems();
break;
case 5:
break;
default:
cout<<"Invalid Output\n" ;
}

}while(x!=5);

Test Cases:

You might also like