Professional Documents
Culture Documents
Q1: Write a program to copy string to another without using buil in function.
Solution:
#include<stdio.h>
#include<string.h>
int main()
{
char original[]="This is to concatenate example";
char copystr[50];
int length,i;
length=strlen(original);
for( i=0;i<length;i++)
{
copystr[i]=original[i];
}
copystr[i]='\0';
printf("String copied = %s",copystr);
}
Q2: Write a program to convert of every word from lowercase to uppercase the string should be entered by
user.
Solution:
#include <iostream>
#include <string>
string Capitalize_first_letter(string t) {
{if (a == 0)
t[a] = toupper(t[a]);
}}
return t;
int main()
return 0;
Q3.
Suppose you are working as a programmer in an IT firm. Your firm got a project to develop an
application for an Ice Cream Parlor. The application must be developed considering the following
scenario.
The application will display a menu showing the flavors that have been offered by the Ice Cream
Parlor.
The Parlor offers Tutti-Frutti, Chocolate, Pineapple, Kulfa, Strawberry, Mango, Orange, and
Pistachio flavors.
The price of each flavor per scoop has been listed in the table below, for multiple scoops, the
price will variate as per the scenario stated in the table.
Three Scoops
Flavor One Scoop Two Scoops
or above
Tutti-Frutti 150 120 100
Chocolate 150 120 100
Pine Apple 150 120 100
Kulfa 150 120 100
Strawberry 150 120 100
Mango 175 150 130
Orange 200 170 150
Pistachio 150 120 100
Solution:
#include <iostream>
int main()
string f;
int scoops;
cout<<"Pineapple"<<" "<<"Kulfa"<<endl;
cout<<"Strawberry"<<" "<<"Mango"<<endl;
cout<<"Orange"<<" "<<"Pistachio"<<endl;
cin>>f;
if(f=="Choclate"||f=="choclate ")
cin>>scoops;
if(scoops==1)
if(scoops==2)
if(scoops>=3)
{
cout<<"The price of each scoop is 100"<<endl;
if(f=="Tutti-Frutti"||f=="tutti-frutti")
cin>>scoops;
if(scoops==1)
cout<<"bill is "<<scoops*150<<endl;
if(scoops==2)
if(scoops>=3)
if(f=="Strawberry"||f=="strawberry")
cin>>scoops;
if(scoops==1)
{
cout<<"bill is RS "<<scoops*150<<endl;
if(scoops==2)
cout<<"bill is RS "<<scoops*120<<endl;
if(scoops>=3)
if(f=="Kulfa"||f=="kulfa")
cin>>scoops;
if(scoops==1)
cout<<"bill is RS "<<scoops*150<<endl;
if(scoops==2)
cout<<"bill is RS "<<scoops*120<<endl;
}
if(scoops>=3)
if(f=="Pineapple"||f=="pineapple")
cin>>scoops;
if(scoops==1)
cout<<"bill is RS "<<scoops*150<<endl;
if(scoops==2)
cout<<"bill is RS "<<scoops*120<<endl;
if(scoops>=3)
cout<<"bill is RS "<<scoops*100<<endl;
if(f=="Pistachio"||f=="pistachio")
if(scoops==1)
cout<<"bill is RS "<<scoops*150<<endl;
if(scoops==2)
cout<<"bill is RS "<<scoops*120<<endl;
if(scoops>=3)
if(f=="Mango"||f=="mango") // mango
cin>>scoops;
if(scoops==1)
cout<<"bill is RS "<<scoops*175<<endl;
if(scoops==2)
if(scoops>=3)
if(f=="Orange"||f=="orange") //orange
cin>>scoops;
if(scoops==1)
cout<<"bill is RS "<<scoops*200<<endl;
if(scoops==2)
cout<<"bill is RS "<<scoops*170<<endl;
if(scoops>=3)
return 0;
}
Q4: Write a C++ Program that change first letter of every word from lowercase to uppercase, the string
should be entered by the user.
SOLUTION:
#include <iostream>
int main()
c=a;
a=b;
b=c;
return 0;
Q5: Write a program in C++ that takes a string from user and your program will count number of words of it
also count the total character in a string.
Solution:
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
char arr[100];
int i,c=1;
cout<<"Enter a string:";
cin>>(arr);
for(i=0;arr[i]!='\0';++i)
if(arr[i]==' ')
c++;
return 0;}
Q6: A car with a 20-gallon gas tank average 21.5 miles per gallon when drive in town and 26.8 miles per
gallon when driven on the highway. Write a program that calculates and displays the distance the car can
travel on one tank of gas when driven in town and when driven on the highway.
Solution:
#include <stdio.h>
#include <math.h>
int main()
{double miles,d;//d=distance
int gallons;
miles=21.5;
gallons=20;
d= miles*gallons ;
miles=26.8;
gallons=20;
d= miles*gallons ;
return 0;
Q7; Write a program that input electricity units consumed and calculate bill according to following
conditions if the units are less than 100 the unit price is Rs. 5 and if the units are more than 100 and less
than 250 then first 100 are charged for Rs. 5 but the rest of the units are charged at Rs 10. If the units are
more than 250 then the first 100 units are charged at Rs. 5 and the rest of the units up to 250 will be
charged at Rs. 10 and the rest units are charged at Rs. 17 and then calculate the total bill for all units.
Solution:
#include <iostream>
int main()
int units;
cin>>units;
int Rs;
if(units<100)
Rs=units*5;
unit=units-100;
a=100*5;
b=unit*10;
Rs=a+b;
}else if(units>250)
int unit,a,b;
int c,d,e;
unit=units-250;
a=unit-100;
c=100*5;
d=250*10;
e=a*17;
Rs=c+d+e;
}return 0;
Q9.Write a program in C++ that take the array elements from the user and search the specific element in
the array. The specific element should be entered from the user which is to be searched. The size of the
array should be 5.
#include<iostream>
int a[size],b,i,c,j,e,f;
cin>>b;
for(i=0;i<b;i++)
cin>>a[i];
cin>>c;
for(j=0;j<b;j++)
e=a[j];
if(e==c)
f=j;
return 0;
Q10. Write a program that will find the roots of quadratic equation if the roots of equation are imaginary
your program will also display those roots.
#include <math.h>
#include <stdio.h>
int main() {
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
else if (discriminant == 0) {
else {
realPart = -b / (2 * a);
}
return 0;