C++ Interview Questions
- 0of 0 votes
AnswersMy code is:
- Rising star June 03, 2023 in United States
#include <iostream>
using namespace std;
struct field{
string f;
string s;
int num;
};
//Function that stores all fiends and foes in altenate manner into single array
//and stores the groups of fiends and foe together in seperate array.
void storesInSingleArr(field arr[], int n, string p[], string q[], string l[], string m[], string b[]){
int ind =0;
for(int i =0;i<n;i++){
//If both are fiends then store first person in array p and and second person store in array q
//and also store both persons in array b
if(arr[i].num == 1){
p[i] = arr[i%n].f;
q[i] = arr[i%n].s;
}
else if(arr[i].num ==0){
l[i] = arr[i%n].f;
m[i] = arr[i%n].s;
}
//if person are not a friend and foe then all person store in all array.
else if(arr[i].f!= "\0"&&arr[i].s!= "\0"){
p[i] = arr[i%n].f;
q[i] = arr[i%n].s;
l[i] = arr[i%n].f;
m[i] = arr[i%n].s;
}
else {
p[i] = arr[i%n].f;
q[i] = arr[i%n].f;
l[i] = arr[i%n].f;
m[i] = arr[i%n].f;
}
}
//finally store altenate of friends and foes in array b.
for(int i =0;i<n;i++){
b[ind++] = p[i];
b[ind++] = l[i];
b[ind++] = q[i];
b[ind++] = m[i];
}
}
void lower(char C){
int asc = C;
if(C>='A' && C<='Z'){
asc = asc+32;
char clower;
clower = asc;
cout<<clower;
}
else if(C>='a' && C<='z')
cout<<C;
}
void lowerIntoUpp(char c){
if(c>='a'&&c<='z'){
c = c-32;
cout<<c;
}
else if(c>='A'&&c<='Z'){
cout<<c;
}
}
void convert(string str){
lowerIntoUpp(str[0]);
for(int i = 1;i<str.length();i++){
lower((str[i]));
}
}
void converToUppLower(field arr[], int n){
string p[n], q[n], l[n], m[n],b[4*n];
storesInSingleArr(arr, n, p, q, l, m, b);
int ind = 0;
for(int i =0;i<n;i++){
b[ind++] = p[i];
b[ind++] =q[i];
b[ind++] =l[i];
b[ind++] = m[i];
}
for(int i =0;i<4*n;i++){
convert(b[i]);
cout<<" ";
}
}
void sort(field arr[], int n) {
string p[n], q[n], l[n], m[n], b[4*n];
//store all friends and foes into single array.
storesInSingleArr(arr, n, p, q, l, m, b);
int i = 0;
bool swapped = true;
while (i < 4*(n - 1) && swapped) {
swapped = false;
for (int j = 0; j < 4*(n - i - 1); j++) {
int k = 0;
while (b[j][k] == b[j + 1][k]) {
k++;
}
if (b[j][k] > b[j + 1][k]) {
string temp = b[j];
b[j] = b[j + 1];
b[j + 1] = temp;
swapped = true;
}
}
i++;
}
for(int i =0;i<4*n;i++){
if(i!= 0){
cout<<" ";
}
cout<<b[i];
}
}
void removeDuplicates(field arr[], int n){
string p[n], q[n], l[n], m[n], b[4*n];
storesInSingleArr(arr, n, p, q, l, m, b);
string r[4*n];
for(int i = 0;i<4*n;i++){
for(int j = i+1;j<4*n;j++){
if(b[i]==b[j]){
b[i] = "remove";
}
}
}
for(int i = 0;i<4*n;i++){
if(b[i]!= "remove")
r[i]= b[i];
}
for(int i =0;i<4*n;i++)
cout<<r[i]<<" ";
}
int main() {
int n;
cin>>n;
field arr[n];
for(int i =0;i<n;i++){
cin>>arr[i].f>>arr[i].s>>arr[i].num;
}
//If input size is greater then 50 then print invalid input.
if(n>50){
cout<<"Invalid Input:";
}
converToUppLower(arr,n);
//cout<<endl;
removeDuplicates(arr, n);
cout<<endl;
sort(arr,n);
return 0;
}
for the input
Jo4e Ma,ry 1
ElizaBet5h June 1
Joe John 0
Joe, JuNe 0
John JUne 1
Margaret
it producing output:
Joe Mary Elizabeth June Joe John Joe June John June Margaret Margaret Margaret Margaret Jo4e Ma,ry ElizaBet5h June Joe Joe, JuNe John JUne Margaret
ElizaBet5h Jo4e Joe Joe, John JuNe John June JUne Ma,ry Margaret Margaret Margaret Margaret
but i want output as:
Diplomats: Elizabeth, Joe, John, June, Margaret, Mary.
Joe, Mary, Elizabeth, June, John, Margaret.
What i am doing mistake in code| Report Duplicate | Flag | PURGE
N/A None C++ - 0of 0 votes
AnswersWrite a C++ Program to Find the Number of Digits in a number.
- hr@ziitech.com April 08, 2022 in India| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWrite a C++ Program to find Factorial of a Number using recursion.
- hr@ziitech.com April 08, 2022 in India| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWrite a C++ Program to find Addition of Two Numbers.
- hr@ziitech.com April 08, 2022 in India| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWrite a C++ Program to find Factorial of a Number using for loop.
- hr@ziitech.com April 08, 2022 in India| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWhat will be the output of the following program?
- hr@ziitech.com April 08, 2022 in India
#include<iostream.h>
class TestDrive
{
int x;
public:
TestDrive(int xx)
{
x = xx;
}
int DriveIt(void);
};
int TestDrive::DriveIt(void)
{
static int value = 0;
int m;
m = x % 2;
x = x / 2;
if((x / 2)) DriveIt();
value = value + m * 10;
return value;
}
int main()
{
TestDrive TD(1234);
cout<< TD.DriveIt() * 10 << endl;
return 0;
}| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWhat will be the output of the following program?
- hr@ziitech.com April 08, 2022 in India
#include<iostream.h>
class IndiaBix
{
int K;
public:
void BixFunction(float, int , char);
void BixFunction(float, char, char);
};
int main()
{
IndiaBix objIB;
objIB.BixFunction(15.09, ‘A’, char(‘A’ + ‘A’));
return 0;
}
void IndiaBix::BixFunction(float, char y, char z)
{
K = int(z);
K = int(y);
K = y + z;
cout<< “K = “ << K << endl;
}| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWhat will be the output of the following program?
- hr@ziitech.com April 08, 2022 in India
#include<iostream.h>
class Bix
{
int x, y;
public:
void show(void);
void main(void);
};
void Bix::show(void)
{
Bix b;
b.x = 2;
b.y = 4;
cout<< x << " " << y;
}
void Bix::main(void)
{
Bix b;
b.x = 6;
b.y = 8;
b.show();
}
int main(int argc, char *argv[])
{
Bix run;
run.main();
return 0;
}| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswerWhat will be the output of the following program?
- hr@ziitech.com April 08, 2022 in India
#include<iostream.h>
int main()
{
float Amount;
float Calculate(float P = 5.0, int N = 2, float R = 2.0);
Amount = Calculate();
cout<< Amount << endl;
return 0;
}
float Calculate(float P, int N, float R)
{
int Year = 1;
float Sum = 1 ;
Sum = Sum * (1 + P * ++N * R);
Year = (int)(Year + Sum);
return Year;
}| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWhat will be the output of the following program?
- hr@ziitech.com April 08, 2022 in India
#include<iostream.h>
class IndiabixSample
{
public:
int a;
float b;
void BixFunction(int a, float b, float c = 100.0f)
{
cout<< a % 20 + c * --b;
}
};
int main()
{ IndiabixSample objBix;
objBix.BixFunction(20, 2.000000f, 5.0f);
return 0;
}| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWrite a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number.
- hr@ziitech.com April 08, 2022 in India
For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWrite a program to calculate HCF of Two given number
- hr@ziitech.com April 08, 2022 in India| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWrite a program to check given number is prime or not
- hr@ziitech.com April 08, 2022 in India| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswerWrite a program to sum of digits of given integer number
- hr@ziitech.com April 08, 2022 in India| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWrite a program to reveres any given integer number
- hr@ziitech.com April 08, 2022 in India| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWrite a program to calculate the sum of first 10 natural number.
- hr@ziitech.com April 08, 2022 in India| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
AnswersWrite a program to print number from 1 to 10.
- hr@ziitech.com April 08, 2022 in India| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
Answers3. What will be the output of the following program?
- hrziisoft April 01, 2022 in India
#include<iostream.h>
double BixFunction(double, double, double = 0, double = 0, double = 0);
int main()
{
double d = 2.3;
cout<< BixFunction(d, 7) << " ";
cout<< BixFunction(d, 7, 6) << endl;
return 0;
}
double BixFunction(double x, double p, double q, double r, double s)
{
return p +(q +(r + s * x)* x) * x;
}| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
Answers2. What will be the output of the following program?
- hrziisoft April 01, 2022 in India
#include<iostream.h>
void MyFunction(int a, int b = 40)
{
cout<< " a = "<< a << " b = " << b << endl;
}
int main()
{
MyFunction(20, 30);
return 0;
}| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 0of 0 votes
Answers1. What will be the output of the following program?
- hrziisoft April 01, 2022 in India
#include<iostream.h>
int BixFunction(int a, int b = 3, int c = 3)
{
cout<< ++a * ++b * --c ;
return 0;
}
int main()
{
BixFunction(5, 0, 0);
return 0;
}| Report Duplicate | Flag | PURGE
Ziisoft Nano Technologies Software Developer C++ - 1of 1 vote
Answers. What is scope resolution operator in C++?
- hr@izetam.com February 02, 2022 in United States
Scope resolution operator in c++ is denoted by double colon (::). It can be used:
– when there is a local variable with same name as of global variable
– When a function has to be defined outside a class
– When class’s static variables needs to be accessed
– When a class inside another class has to be referred
– In case of multiple Inheritance| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersWhat is an expression in C++?
- hr@izetam.com February 02, 2022 in United States
An expression is a combination of operators, constants and variables. There seven types of expressions for examples:
– Constant expressions: 89 +10/4.0
– Integral expressions: x * y
– Floating expressions: 17.89
– Relational expressions: a<=b
– Logical expressions: a > b && a == 7
– Pointer expressions: *ptr
– Bitwise expressions: p << 5| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersWhat is a reference variable in C++?
- hr@izetam.com February 02, 2022 in United States
When a variable is declared as a reference, it becomes an alternative name for an existing variable. A variable can be declared as a reference by putting ‘&’ in the declaration.| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersWhat is conio.h in C++?
- hr@izetam.com February 02, 2022 in United States
Conio.h is a header file used for console input and output operations and is used for creating text based user interfaces.| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersHow to set decimal places in C++ ?
- hr@izetam.com February 02, 2022 in United States
For limiting the decimal places in C++ there are five functions : floor(), ceil(), trunc(), round() and setprecision(). Out of these five, only setprecision() function is used for setting the decimal places to put as output| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersWhat is type casting in C++?
- hr@izetam.com February 02, 2022 in United States
Type casting in C is used to change the data type. They are of two types: Implicit Type Conversion: It is automatic. Explicit Type Conversion: It is user-defined.| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersHow to paste in turbo C++?
- hr@izetam.com February 02, 2022 in United States
Paste in turbo C++ can be done by two techniques:
1. Shift+Insert
2. Open the file in notepad with .cpp extension. Make the changes and save it. After saving the file, you can open it from the Turbo C++ application file menu from where you stored the cpp file.| Report Duplicate | Flag | PURGE
C++