0% found this document useful (0 votes)
2 views8 pages

Codes 2

Uploaded by

harishjain086
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)
2 views8 pages

Codes 2

Uploaded by

harishjain086
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/ 8

1..

Program using string functions:

#include<iostream>

Using namespace std;

Int main(){

Cout<<”OUTPUT:”<<endl;

String first=”Raspberry”;

String second=”Pi”;

String third=first+second;

//concatenation using +

String fourth-first.append(second);

//append() is faster than +

Cout<<third<<endl;

10

116

Cout<<fourth<<endl;

Cout<<first.size()<<endl;

//you can also use length()


12

Return 0;

13

PROBLEMS OUTPUT DEBUG CONSOLE

TERMINAL PORTS

PS C:\Users\Anmol\OneDrive\Documents\c++ programs\college_practice\30-01-24> cd “c:\User: \


college_practice\30-01-24\”; if ($?) { g++ string_functions.cpp -o string_functions }

OUTPUT:

RaspberryPi RaspberryPi

11

Program using string indexing:

13

+ in 17

#include<iostream>

Using namespace std; int main(){

Cout<<”OUTPUT:”<<endl;

String greet=”Hello”;

Cout<<greet<<endl; greet [0]=’F’;

Cout<<greet[0]<<endl;

Cout<<greet<<endl; return 0;
8

10

11

PROBLEMS

OUTPUT

TERMINAL DEBUG CONSOLE

PORTS

PS C:\Users\Anmol\OneDrive\Documents\c++ programs\college_practice\36 \college_practice\30-01-


24\”; if ($?) { g++ string_index.cpp -o stri

OUTPUT:

Hello

Fello

3..

Program using getline() function:

#include<iostream>

Using namespace std;

Int main(){

6
7

10 }

String fullname;

Cout<<”OUTPUT:”<<endl;

Cout<<”Enter your full name:”;

Getline(cin, fullname);

Cout<<”Your name is:”<<fullname; return 0;

PROBLEMS

OUTPUT

DEBUG CONSOLE

TERMINAL PORTS

PS C:\Users\Anmol\OneDrive\Documents\c++ programs\college_practice\30-01-24> \college_practice\


30-01-24\”; if ($?) { g++ getline_func.cpp -o getline_fun

OUTPUT:

Enter your full name: Anmol Kumar Agrawal

Your name is: Anmol Kumar Agrawal

Program using cmath:

10

11

44

#include<iostream>

#include<cmath>
Using namespace std;

Int main()

Cout<<”OUTPUT:”<<endl; cout<<sqrt(144) <<endl; cout<<round (3.6) <<endl; cout<<log(3)<<endl;


cout<<max(10,12) <<endl; return 0;

PROBLEMS

OUTPUT

DEBUG CONSOLE

TERMINAL PORTS

PS C:\Users\Anmol\OneDrive\Documents\c++ programs\college_practi \college practice\30-01-24\”; if


($?) { g++ cmath.cpp -o cmath

OUTPUT:

12

1.09861

12

5.

Program using shorthand if else:

1 #include<iostream>

2 using namespace std;

Cout<<”OUTPUT:”<<endl;

Int main(){

5
6

10}

PROBLEMS

Int time=17;

String result=(time <=17)? “good day.”:”good evening.”;

Cout<<result;

Return 0;

OUTPUT DEBUG CONSOLE TERMINAL PORTS

PS C:\Users\Anmol\OneDrive\Documents\c++ programs\college_practice\38-01-24> cd “c:\Users\Anmx


ograms\college_practice\30-01-24\”; if ($?) { g++ shorthand_ifelse.cpp -o shorthand_ifelse }

Ise }

OUTPUT:

Good day.

Program using switch:

2 3 4 in

67899

10

11

12
13

11

4 in

14

15

16

#include<iostream>

Using namespace std; int main(){ int day=5; switch(day) {

Case 1:

Cout<<”Monday”;

Break;

Case 2:

Cout<<”Tuesday”;

Break;

Case 3:

Cout<<”Wednesday”;

Break;

Case 4:

Cout<<”Thursday”;

Break;

Case 5:

Cout<<”Friday”;

Break;

Case 6:

Cout<<”Saturday”;

Break;

17

18

19
20

21

22

23

24

25

26

Default:

27

Cout<<”invalid”;}

28

Return 0;}

Case 7:

Cout<<”Sunday”;

Break;

OUTPUT:

Friday

You might also like