You are on page 1of 16

Winter-2019

Semester
COMP 150 (Introduction to
Programming)

C++ Coding
Assignment 1

Submitted to:
Prof. Siddhartha Shyam Vyas

Submitted by:
Manav Babbar (300166069)
BCIS 1st Year 2nd Semester

Date of Submission:11th March 2019


TABLE OF CONTENTS

S. No. CONTENTS Page


Number
1 CERTIFICATE OF ORIGINALITY i

2 ACKNOWLEDGEMENT ii

3 Write a program to display a simple string - 'Welcome to C++ programming'. 1

4 Write a program to assign values to two different integer variables and print their 2
sum.
5 Write a program to assign a character to a character variable and print the character 3
along with its ASCII value. Do not use typecasting for the same
6 Write a program to take character as a user input and print the character along with 4
its ASCII value. Use type-casting to print the character's ASCII value.
7 Write a program to take character as a user input between 'a' to 'v' and then print the 5
next 4 characters.

8 Write a program to divide two integer values and display the result in floating-point. 6
Use typecasting for the same.

9 Write a program to take two user inputs, calculate their sum and then print it. 7
10 Write a program to take a user input and find square of that number. 8
11 Write a program to take a user input and find the cube of a given number. 9
12 Write a program to take marks scored in 5 subjects (out of 100) from the user. 10
Compute the total marks and print the percentage calculated.
13 REFERENCES 11
CERTIFICATE OF ORIGINALITY
I hereby declare that:
 I have used my own words
 I have not copied
 I have not plagiarized
 I have cited all the sources from where I have adapted / sourced
Manav Babbar (300166069)
Signature: -
ACKNOWLEDGEMENT
We want to express our profound gratefulness to our Prof. Siddhartha Shyam Vyas,
Ph.D………………………………………………………………………….

Manav Babbar (300166069)


Signature: -
NOTE:
Dear student,

There should be no page# in the footer section of FRONT PAGE, TABLE OF CONTENTS.

ACKNOWLEDGEMENT & CERTIFICATE OF ORIGINALITY pages will have Roman Numeral page# in the
footer section as specified in the TABLE OF CONTENTS (i) (ii)

CERTIFICATE OF ORIGINALITY must remain exactly the same as shown in the document. The name of
the student must be typed neatly with hand-signatures using a blue / black pen beside it.

Please check the ACKNOWLEDGEMENT part. However, you can modify it further by adding more people
you have connected with apart from your COMP150 professor for the assignment. The name of the student
must be typed neatly with hand-signatures using a blue / black pen beside it.

The normal page# like: 1, 2 etc. in the footer section must start from Question 1 of the ASSIGNMENT. Also,
the first question should be written completely followed by the code for the question typed neatly and
legibly. Once the code part is done, then also put the screen-shot of the output below it. Every question of
the assignment must start from a fresh new page.

If you have consulted any organization, you should have a good explanation of how efficient is the
algorithm that you are typing for the program compared to what is done and shown to you all in the class.
Also, you can always give a brief overview of the organization consulted and then start the Question 1 from
the fresh new page for the assignment. Kindly staple the visiting cards of people if consulted any, with
regard to your assignment. If visiting cards aren't available, kindly mention the following: Name of the
person, Telephone/ cell number, email-id, designation, organization name

REFERENCES must start from a new page. No page# required in the footer section of REFERENCES
page. REFERENCES must be in APA Style format. If no references are there, then it must be written in the
“REFERENCES” section as – NO REFERENCES AVAILABLE FOR THIS ASSIGNMENT.

FONT STYLE: is your choice but must look professional, neat & tidy.

HEADING FONT-SIZE: 16 pts

SUB-HEADING FONT-SIZE: 14 pts

NORMAL FONT-SIZE OF CONTENTS: 12 pts

Assignments shall be communicated to the students in the class and via email. The due date of assignment
submission has been mentioned in the course outline.

Answers: -
1. Write a program to display a simple string - 'Welcome to C++
programming'.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char sentence[20];
//Taking a character input "sentence" for displaying single
string//
cout<<"Welcome to C++ Programming ";
cin>>sentence;
// Executing Simple String " sentence" with the sentence
"Welcome to C++ Programming"//
getch();
}
2. Write a program to assign values to two different integer variables and
print their sum.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num1=0,num2=0,sum=0;
cout<<"Enter 2 Variables: ";
cin>>num1>>num2;
sum=num1+num2;
cout<<"The sum is= "<<sum;
getch();
}
3. Write a program to assign a character to a character variable
and print the character along with its ASCII value. Do not use
typecasting for the same.

#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
char var;
cout<<"Enter a character= ";
cin>>var;
cout<<"ASCII Value of "<< var <<" is "<< int(var);//type-
casting not being done in converting character variable into
integer variable//
getch();
return 0;
}
4. Write a program to take character as a user input and print the
character along with it's ASCII value. Use type-casting to
print the character’s ASCII Value.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int var;
cout<<"Enter the variable btw 65 - 90 for upper case
letters and 97 - 122 for lower case letters: ";
cin>>var;
char var1=var;
cout<<var1;
getch();
}
5. Write a program to take character as a user input between 'a'
to 'v' and then print the next 4 characters.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char bmw;
cout<<"Enter the character btw a to v: ";
cin>>bmw;
int number=bmw;
cout<<"\n\t Next 4 Characters are: ";
cout<<"\n"<<++bmw;
cout<<"\n"<<++bmw;
cout<<"\n"<<++bmw;
cout<<"\n"<<++bmw;
getch();
}
6. Write a program to divide two integer values and display the result in
floating-point. Use typecasting for the same.
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr ();
int var1=0, var2=0;
cout<<"1st value= ";
cin>>var1;
cout<<"2nd value= ";
cin>>var2;
float outcome;
outcome=(float)var1/var2;
cout<<"Result with type casting is: "<<outcome;
getch();
}

7. Write a program to take two user inputs, calculate their sum and
then print it.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int value1,value2,value3;
cout<<"Enter the value in a= ";
cin>>value1;
cout<<"Enter the value in b= ";
cin>>value2;
value3=value1+value2;
cout<<"The sum of "<<value1<<" & "<<value2<<" are: "<<value3;
getch();
}

8. Write a program to take a user input and find square of that


number.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
double var, square;
cout<<"Please enter a variable= ";
cin>>var;
square=var*var;
cout<<"\n\t* Square of the no is= "<<square;
getch();
}

9.Write a program to take a user input and find the cube of a


given number.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
double var,cube;
cout<<"Please enter a variable= ";
cin>>var;
cube=var*var*var;
cout<<"\n\t* Cube of the no is= "<<cube;
getch();
}
10.Write a program to take marks scored in 5 subjects (out of 100) from the user.
Compute the total marks and print the percentage calculated.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int average,english,maths,hindi,socialscience,science;
float total;
cout<<"Enter the no of marks scored in English out of 100: ";
cin>>english;
cout<<"Enter the no of marks scored in Maths out of 100: ";
cin>>maths;
cout<<"Enter the no of marks scored in Hindi out of 100: ";
cin>>hindi;
cout<<"Enter the no of marks scored in Social Science out of 100: ";
cin>>socialscience;
cout<<"Enter the no of marks scored in Science out of 100: ";
cin>>science;
total=english+maths+hindi+socialscience+science;
average=(total/500)*100;
cout<<"\n\tTotal Marks: "<<total;
cout<<"\n\tAverage marks is: "<<average<<" %";
getch();
}

You might also like