السلام عليكم ورحمة الله وبركاته
هل في فرق بين int و void في لغة ++c
18 груд 2024, 03:02
• نصائح واستشارات برمجية متعلقة باسئلة تم طرحها • لطرح استفسار او سؤال: @m4md24
Показати більшеهو يفضل قبل البدأ في ASP .NET ابدأ بِــــSQL الاول وبعدها بالــــــــــ#Cالإجابة بتبدأ بلغة C# و بالمنتصف لما توصل لقواعد البيانات بتدرس SQL و بتستكمل C#، المفاهيم ما خلصت عند ال Database
عندي استفسار : السلام عليكم ورحمة الله يا اخوان انا محتار في اني اتعلم تطوير الويب وفيه مسارين قدامي : مسار بايثون مع جانقو مسار جافاسكريبت والسبب اني ابرمج في بايثون بشكل مقبول يعني ودي اروح مع جانقو لكن جانقو في front end مو ممتازة لكن في back end ممتازة جداً . و جافاسكريبت يبي لي اتعلمها و اتعلم MERN معاها و موضوعها بيطول و اصعب بكثير انا شايل هم الواجهات لأن عندي مشاريع وهمي الواجهات ، اتمنى احد يفيدنيالإجابة و عليكم السلام و رحمة الله اختار اللي تحبه أكثر، مجالات البرمجة مطلوبة نسبياً الفكرة أنك تجتهد باللي تحبه أكثر حتى تبدع فيه بإذن الرحمن
#include <iostream>
using namespace std;
struct Node {
int value;
Node* next;
// Constructor
Node(int val) {
value = val;
next = nullptr;
}
};
class LinkedList {
private:
Node* head;
public:
// Constructor
LinkedList() {
head = nullptr;
}
// 1. Insert at the front
void insert_front(int value) {
Node* new_node = new Node(value);
new_node->next = head;
head = new_node;
}
// 2. Insert at a specific position
void insert_position(int position, int value) {
if (position == 0) {
insert_front(value);
return;
}
Node* new_node = new Node(value);
Node* current = head;
for (int i = 0; i < position - 1; i++) {
if (current == nullptr) {
cout << "Position out of range!" << endl;
return;
}
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
// 3. Insert at the end
void insert_last(int value) {
Node* new_node = new Node(value);
if (head == nullptr) {
head = new_node;
return;
}
Node* current = head;
while (current->next != nullptr) {
current = current->next;
}
current->next = new_node;
}
// 4. Delete from the front
void delete_front() {
if (head == nullptr) {
cout << "List is empty!" << endl;
return;
}
Node* temp = head;
head = head->next;
delete temp;
}
// 5. Delete at a specific position
void delete_position(int position) {
if (head == nullptr) {
cout << "List is empty!" << endl;
return;
}
if (position == 0) {
delete_front();
return;
}
Node* current = head;
for (int i = 0; i < position - 1; i++) {
if (current == nullptr || current->next == nullptr) {
cout << "Position out of range!" << endl;
return;
}
current = current->next;
}
Node* temp = current->next;
current->next = temp->next;
delete temp;
}
// 6. Delete from the end
void delete_last() {
if (head == nullptr) {
cout << "List is empty!" << endl;
return;
}
if (head->next == nullptr) {
delete head;
head = nullptr;
return;
}
Node* current = head;
while (current->next->next != nullptr) {
current = current->next;
}
delete current->next;
current->next = nullptr;
}
// 7. Display the list
void display() {
if (head == nullptr) {
cout << "List is empty!" << endl;
return;
}
Node* current = head;
while (current != nullptr) {
cout << current->value << " -> ";
current = current->next;
}
cout << "NULL" << endl;
}
// 8. Count the number of nodes
int count() {
int count = 0;
Node* current = head;
while (current != nullptr) {
count++;
current = current->next;
}
return count;
}
};
int main() {
LinkedList list;
list.insert_front(10);
list.insert_last(20);
list.insert_last(30);
list.insert_position(1, 15);
list.display();
cout << "Count: " << list.count() << endl;
list.delete_front();
list.display();
list.delete_last();
list.display();
list.delete_position(1);
list.display();
cout << "Count: " << list.count() << endl;
return 0;
}#include <iostream>
using namespace std;
int main() {
const int MAXIMUM_STARS = 4;
for (int currentRow = 1; currentRow <= 2 * MAXIMUM_STARS - 1; currentRow++) {
int stars = (currentRow <= MAXIMUM_STARS) ? currentRow : 2 * MAXIMUM_STARS - currentRow;
for (int column = 0; column < stars; column++)
cout << "*";
cout << std::endl;
}
return 0;
}#include <iostream>
#include <string>
using namespace std;
// Example 1: str.size() / str.length()
void exampleSizeLength() {
string str = "Hello";
cout << "String length: " << str.size() << endl; // Or str.length()
}
// Example 2: str.push_back(char)
void examplePushBack() {
string str = "Hello";
str.push_back('!');
cout << "After push_back: " << str << endl;
}
// Example 3: str.pop_back()
void examplePopBack() {
string str = "Hello!";
str.pop_back();
cout << "After pop_back: " << str << endl;
}
// Example 4: str.erase(pos, len)
void exampleErase() {
string str = "Hello, World!";
str.erase(5, 7); // Remove 7 characters starting from index 5
cout << "After erase: " << str << endl;
}
// Example 5: str.substr(pos, len)
void exampleSubstr() {
string str = "Hello, World!";
string subStr = str.substr(7, 5); // Extract 5 characters starting from index 7
cout << "Substring: " << subStr << endl;
}
// Example 6: str.resize(newSize)
void exampleResize() {
string str = "Hello";
str.resize(8, '*'); // Resize to 8 characters, filling with '*'
cout << "After resize: " << str << endl;
}
// Example 7: str.insert(pos, subStr)
void exampleInsert() {
string str = "Hello!";
str.insert(5, ", World");
cout << "After insert: " << str << endl;
}
// Example 8: str.back()
void exampleBack() {
string str = "Hello!";
cout << "Last character: " << str.back() << endl;
}
// Example 9: getline(cin, str)
void exampleGetline() {
string str;
cout << "Enter a string: ";
getline(cin, str);
cout << "You entered: " << str << endl;
}
int main() {
exampleSizeLength();
examplePushBack();
examplePopBack();
exampleErase();
exampleSubstr();
exampleResize();
exampleInsert();
exampleBack();
exampleGetline();
return 0;
}