OOP: Batch-23, Lecture-01

#include<iostream>
using namespace std;
class Teacher; // class declaration
//declaration and definition
//class member: private, public, protected
class Student //Structure / Template for an object
{
int roll; // data member/attribute/property
char name[30];
int semester;
char section;
float cgpa; 

public:
void get_data()
{
cout << "Enter roll: ";
cin >> roll; // cin input object
cout <<"Enter Name: ";
cin >> name;
}
void show_data(); // member function declaration
float get_cgpa();
}s1;

//defining a member function
void Student::show_data() // :: >> scope resolution
{
cout << " --- Student info --- "<<endl;
cout << "Roll: " << roll << endl; // endl == '\n'
cout << "Name: " << name << endl;
}

int main()
{
Student s2; // Single object / variable
Student s[60]; // Array of object

cout<<"Enter student 1 info: ";
s1.get_data(); // accessing member via object

cout<<"Enter student 2 info: ";
s2.get_data();

cout<<"Enter student 3 info: ";
s[0].get_data();

s1.show_data();
s2.show_data();
s[0].show_data();

//s3 = s1 + s2; // Operator Overloading

return 0;
}

Write a C program to display the digits of a number as pyramid

(i)    Given an integer number, write a program that displays the number as follows :

First Line       : all digits
Second Line   : all excepts first digits
Third Line      : all excepts first two digits
………..
Last Line        : the last digit.
For example, the number 5678 will be displayed as :

5         6          7          8
6         7          8
7         8
8

Solution: 
#include<stdio.h>
int main(){
int x,arr[16],i=0,j;
printf("Enter the integer value: ");
scanf("%d",&x);
while(x > 0){
arr[i]= x % 10;
x = x / 10;
i++;
}
for(j=i-1; j >= 0; j--){
for(i=j; i>=0;i--){
printf("%d ",arr[i]);
}
printf("\n");
}
return 0;
}

Posted in CSE

Software Engineering Practical using PHP/MySQL

Software project: Desktop / Web based
Platform: any

Backend Language: PHP/MYSQL
Frontend: HTML + CSS + JS
Server: Local server (XAMPP/WAMP) / Web Server
Text Editor: Notepad++ / Sublime Text/ VS code etc.

1. Install XAMPP. Download from: https://www.apachefriends.org/download.html
2. Start xampp control panel
3. Start PHP (Apache) and MySQL service
4. Click ‘Explorer’ >> htdocs folder (server root)
5. Create project folder ’21q’
6. Create index.html / index.php file in ’21q’ folder
7. Write some html code in index file
8. Browse http://localhost/21q from any browser e.g. Google chrome
Note: browsing localhost/21q will automatically run the index file.
9. Create a php file test.php and write some php code then browse http://localhost/21q/test.php
Note: to run php program file we must use Local/web server. PHP code must be written in php tag (<?php //program code here… ?> )
10. Create a database and a table in database server by browsing http://localhost/phpmyadmin from any browser
11. Write php code using php/mysql functions to connect and query in database

H.W
1. ICT book chapter – 4
2. W3schools.com HTML tutorial / or anywhere

Programming Language in C Practical List

Section – 1 (Introduction, Constant, Variables, Data Types, Operators, Expressions, Decisions Making, Branching and Looping)       (Answer any two)                                        15 ´ 2 = 30

 

(a)   Write a program to find the area of a circle. (Use p as a symbolic constant).

(b)   Write a program to convert the given temperature in Fahrenheit to Celsius and vice versa.

(c)   Write a program to find the all-possible roots of a quadratic equation.

(d)   Write a program that takes a floating-point number as input and display the floating point and integer part separately.

(e)   Write a program to find the factorial of an integer.

(f)   Write a program that takes an integer as input and display it in reverse order.

(g)   Write a program to convert any integer to its binary equivalent.

(h)   Write a program in C to determine and print the sum of the following harmonic series for a given value of n : s = 1 + 1/22 + 1/33 …….. + 1/nn.

(i)    Given an integer number, write a program that displays the number as follows :

First Line       : all digits

Second Line   : all excepts first digits

Third Line      : all excepts first two digits

………..

Last Line        : the last digit.

For example, the number 5678 will be displayed as :

5         6          7          8

6         7          8

7         8

8

(j)    Write a program in C that prints the smallest of the three numbers.

(k)   Write a program in C to compute the sum of the digits of a given integer number. For example, if the input number is 123 then output should be 6.

 

 

Section – 2 (Arrays, Character Arrays, Strings, User-Defined Functions and Structures) (Answer any one)                                                                                                                15 ´ 1 = 15

 

(a)   Write a program to multiply two matrices.

(b)   Write a program to initialize all the diagonal elements of a two-dimensional array to 1 and others to 0.

(c)   Write a program that reads a string from keyboard and determines whether it is a palindrome or not.

(d)   Write a program to evaluate the expression using user defined function:

f(x) = x-x3/3! + x5/5!-x7/7!+…..

(e)   Write a program to find the first n Fibonacci numbers.

(f)   Write a program using an array of structure to read the number of three subjects for n students and sort them according to their position. (1st, 2nd, 3rd ……)

(g)   Given two one-dimensional arrays A and B which are sorted in ascending order. Write a program to merge them into a single sorted array C that contains every item from arrays A and B, in ascending order.

(h)   Write a program to copy one string into another and count the number of characters copied.

(i)    Write a program in C to concatenate the three arrays namely first-name, second-name, third-name into one string to be called name.

 

Section – 3 (Pointers and File Management) (Answer any one)                                  15 ´ 1 = 15

 

(a)   Write a program using pointers to read  an array of integers and print its elements in reverse order.

(b)   Write a program using pointers to compute the sum of all elements stored in an array.

(c)   Write a program to copy the contents of one file into another.

(d)   Write a program to read data from keyboard, write it to a file called, INPUT, again read the same data from the INPUT file and display it on the screen.

(e)   Write a program that appends one file at the end of another.

(f)   Write a program to open a file named INVENTORY and store in it the following data :

Item Name                  Number                    Price                   Quantity

AAA-1                        123                       15.55                       150

BBB-2                        125                       36.12                       175

CCC-3                        527                       32.15                       115

Extend the program to read this data from the file INVENTORY and display the inventory table with the value of each item.

CodeBlocks – C and C++ Compiler Software

  1. Download and install Compiler software (CodeBlocks).
    http://www.codeblocks.org/downloads/binaries/Download your  version compatible with your system. Notice ‘mingw’ word in the file name. Because ‘mingw’ is the compiler included in CodeBlocks software.
    Ex: codeblocks-20.03mingw-setup.exe
  2. Open New file ( File >> New >> Empty file )
  3. Save the file ‘welcome.c’ or ‘welcome.cpp’
  4. Write the sample code given below:
    C Program File Name: welcome.c
    #include<stdio.h>
    void main()
    {
    printf("Welcome to C Programming!");
    }

    C++ Program File Name: welcome.cpp
    #include<iostream>
    using namespace std;
    int main()
    {
    cout << "Welcome to C++ Programming!";
    return 0;
    }
     
  5. Compile/Build the file ( Build Menu >> Build ) or keyboard Shortcut ‘Ctrl+F9’
  6. Run/Execute the file (Build Menu >> Run ) or keyboard Shortcut ‘Ctrl + Shift + F9’
  7. Success! Your are ready for programming.