0% found this document useful (0 votes)
90 views

#Include Int Main (Cout "Welcome To C++ Programing" Return )

This document provides instructions for an assignment due on May 30th 2020. It includes converting sample C programs to C++ and writing new C++ programs. The tasks are: [1] Converting 6 C programs to C++ by replacing headers and functions. [2] Writing 3 C++ programs - to swap variables without a third, find largest of 3 numbers using ternary operator, and convert days to years/months/days. [3] Answering questions about Object Oriented Programming and differences between C and C++. The document provides sample C code and instructions for each conversion.
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)
90 views

#Include Int Main (Cout "Welcome To C++ Programing" Return )

This document provides instructions for an assignment due on May 30th 2020. It includes converting sample C programs to C++ and writing new C++ programs. The tasks are: [1] Converting 6 C programs to C++ by replacing headers and functions. [2] Writing 3 C++ programs - to swap variables without a third, find largest of 3 numbers using ternary operator, and convert days to years/months/days. [3] Answering questions about Object Oriented Programming and differences between C and C++. The document provides sample C code and instructions for each conversion.
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/ 4

Week-1: Assignment-1

Due date: 30th May 2020 – [11:59PM]

Roll no
Name

Complete all the tasks as per the instructions given.

Task-1
=====
Convert all the following C program codes into C++ programming Codes.

Program-1
// A first program in C language.
#include<stdio.h>
#include<conio.h>
void main()
{
printf(“Welcome to C Programming”);
getch();
}
Sample Solution: Program-1

#include<iostream>
Int main()
{
cout << “Welcome to C++ Programing”;
return ;
}

NOTE: conio.h is not required while working in Dev C++. Also calling the clrscr() function
for clearing the screen and getch() function for holding the screen are not required.

Program-2
#include<stdio.h>
void main()
{
int a,b,c;
printf(“Enter the first number : “ );
scanf(“%d”, &a);
printf(“Enter the second number: “);
scanf(“%d”, &b);
c=a+b;
printf(“The sum of numbers is %d” ,c);
}
Program-3
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("Enter a number");
scanf("%d",&num);
i=num%2;
if(i==0)
{
printf(“Even number!”);
}
else
{
printf(“Odd number!”);
}
getch();
}

Program-4

#include<stdio.h>
#include<conio.h>
void main()
{
int day;
clrscr();
printf("Enter the days of a week:");
scanf("%d",&day);
switch(day)
{
case 1:
printf("Sunday");
break;
case 2:
printf("Monday");
break;
case 3:
printf("Tuesday");
break;
case 4:
printf("Wednesday");
break;
case 5:
printf("Thursday");
break;
case 6:
printf("Friday");
break;
case 7:
printf("Saturday");
break;
default:
printf("Invalid day number!");
break;
}
getch();
}

Program-5
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
printf("%d\n",i);
}
getch();
}

Example-6
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
printf("*");
}
printf("\n");
}
getch();
}
Task-2
=====

Write C++ programs for the following questions given. Your answer should also include
output of programs.

1. Write a program to swap value of two variables without using third variable.
2. Write a program which input three numbers and display the largest number using ternary
operator.
3. Write a program which accepts days as integer and display total number of
years, months and days in it.

Task-3
=====

Answer the following questions.

1. What is Object Oriented Programming?


2. Write difference between C language and C++ language.

You might also like